# Performance Evaluation of Open-Source Serverless Platforms for Kubernetes
### Appendix A.1 Listing A1  
Image processing serverless function code. The function first receives the input data via stdin (Line 10-13) and then loads it into a Blob (Line 15-17), which is a data type defined by ImageMagick for holding binary image data. Afterwards, it creates an Image object from the Blob (Line 18), which is another ImageMagick data type. Using this Image object, a set of image operations is applied (Line 20-28) that require roughly 1.3 seconds of compute time on the target CPU. Afterwards, it extracts the now modified Blob from the Image object (Line 30-32) and writes it back as binary data via stdout (Line 33-37). The NP variant uses the same code, except instead of performing image transformations (Line 20-28), it calls sleep(1). ```
1#include<Magick++.h>
2#include<iostream>
3
4 usingnamespaceMagick;
5
6 intmain()
7{
8 try{
9//Donotskip whitespaceswhiler reading
10 std::cin>>std::noskipus;
11 std::stream_iterator<char>it(std::cin);
12 std::istream_iterator<char>end;
13 std::stringinput(it,end);
14//Converstringt unsignedchar*tocconstvoid*soBlobcanuseit
15 autoinput_c=reinterpret_cast<constunsignedchar*>(input.c_str());
16 constvoid*input_cw=static_cast<constvoid*>(input_c);
17 Blob blob(input_cv,input.size());
18 Imageimage(blob);
19//Performimagetransformations
20 image.blur(1,0.5);
21 image.addNoise(MultiplicativeGaussianNoise, 1);
22 image.addNoise(LaplacianNoise, 1);
23 image.enhance();
24 image.negate();
25 image.normalize();
26 image.reduceNoise();
27 image.swirl(37);
28 image.wave();
29//Convertimagebacktoblob
30 Blobout;
31 image.magick(\"PNG\");
32 image.write(&out);
33 constvoid*out_cv=out.data();
34 size_tout_size=out.length();
35//Andwritetostdout
36 std::stringout_str(static_cast<constchar*)(out_cv),out_size);
37 std::cout<<out_str;
38 return0;
39 catch(Exception&error_)
40{
41 std::cout<<\"Caughtexception:\"<<error_what()<<std::endl;
42 return1;
43}

### Appendix A.2

**Listing A2**. Byte reversal workload--Serverless C++ function code. The C++ implementation of the byte reversal serverless function uses the same stream mechanisms for reading and writing to and from stdin and sdout as the image processing implementation shown in Appendix A.1. Reversal of bytes is performed using the reverse function from the C++ standard library (Line 13). ```
1#include<iostream>
2#include<bits/stdc++.h>
3
4 intmain(int argc,char**argv)
5{try{
7//Donotskipwhitespaceswhilereading
8 std::cin>>std::inoskipw;
9 std::istream_iterator<char>it(std::cin);
10 std::istream_iterator<char>end;
11 std::string_input(it,end);
12//Reverse(inputandsenditback
13 reverse(input.begin(),input.end());
14 std::cout<<input;
15}
16 catch(ExceptionError_)
17{
18 std::cout<<\"Caughtexception:\"<<error_.what()<<std::endl;
19 return1;
20}
21 return0;
22}
```
### Appendix A.3

**Listing A3**. Byte reversal serverless Go function code. The Go implementation of the byte reversal workload does not need to handle streams and can instead directly handle object references passed to it as function parameters. The user function implements an interface defined by the Nuclio Go SDK (Line 7). As Go has no reverse function in its standard library, this is instead implemented as a loop (Line 10-12). ```
1 packagemain
2
3 import(
4\"github.com/nuclio/nuclio-sdk-go\"
5)
6
7 funcHandler(context*nuclio.Context,eventnuclio.Event)(interface{},error){
8b:=event.GetBody()
9//Reversebytesofinput
10 fori,j:=0,len(b)-1;i<j;i,j=i+1,j-1{
11b[i],b[j]=b[j],b[i]
12}
13 returnnuclio.Response{
14 StatusCode:200,
15 ContentType:\"application/text\",
16 Body:b,
17},nil
18}
```





[PERSON]; [PERSON]; [PERSON] FaaSter, Better, Cheaper: The Prospect of Serverless Scientific Computing and HPC. In Proceedings of the High Performance Computing, Dresden, Germany, 11-12 September 2017; [PERSON], [PERSON], Eds. ; Communications in Computer and Information Science; Springer International Publishing: Cham, Switzerland, 2018; pp. 154-168.