diff --git a/benchmarks/image-rotate/Makefile b/benchmarks/image-rotate/Makefile new file mode 100644 index 000000000..cab807c7b --- /dev/null +++ b/benchmarks/image-rotate/Makefile @@ -0,0 +1,58 @@ +# MIT License + +# Copyright (c) 2024 EASE lab + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +ROOT = ../../ + +all-image: image-rotate-python image-rotate-go init-database + +image-rotate-python: docker/Dockerfile python/server.py python/requirements.txt images/default.jpg + DOCKER_BUILDKIT=1 docker build \ + --tag vhiveease/image-rotate-python:latest \ + --target imageRotatePython \ + -f docker/Dockerfile \ + $(ROOT) --load + +image-rotate-go: docker/Dockerfile go/server.go go/go.mod go/go.sum images/default.jpg + DOCKER_BUILDKIT=1 docker build \ + --tag vhiveease/image-rotate-go:latest \ + --target imageRotateGo \ + -f docker/Dockerfile \ + $(ROOT) --load + +init-database: docker/Dockerfile init/init-database.go images/default.jpg + DOCKER_BUILDKIT=1 docker build \ + --tag vhiveease/image-rotate-init-database:latest \ + --target databaseInit \ + -f docker/Dockerfile \ + $(ROOT) --load + +## Push images +push: + docker push docker.io/vhiveease/image-rotate-init-database:latest + docker push docker.io/vhiveease/image-rotate-python:latest + docker push docker.io/vhiveease/image-rotate-go:latest + +## Pull images from docker hub +pull: + docker pull docker.io/vhiveease/image-rotate-python:latest + docker pull docker.io/vhiveease/image-rotate-go:latest + docker pull docker.io/vhiveease/image-rotate-init-database:latest diff --git a/benchmarks/image-rotate/docker/Dockerfile b/benchmarks/image-rotate/docker/Dockerfile new file mode 100644 index 000000000..f882e3f31 --- /dev/null +++ b/benchmarks/image-rotate/docker/Dockerfile @@ -0,0 +1,87 @@ +# MIT License + +# Copyright (c) 2024 EASE lab + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +#---------- Init-Database -----------# +# First stage (Builder): +FROM vhiveease/golang-builder:latest AS databaseInitBuilder +WORKDIR /app/app/ +RUN apt-get install git ca-certificates + +COPY ./benchmarks/image-rotate/init/go.mod ./ +COPY ./benchmarks/image-rotate/init/go.sum ./ +COPY ./benchmarks/image-rotate/init/init-database.go ./ + +RUN go mod tidy +RUN CGO_ENABLED=0 GOOS=linux go build -v -o ./init-database init-database.go + +# Second stage (Runner): +FROM scratch as databaseInit +WORKDIR /app/ +COPY --from=databaseInitBuilder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=databaseInitBuilder /app/app/init-database . +COPY ./benchmarks/image-rotate/images/ ./images + +ENTRYPOINT [ "/app/init-database" ] + + +#---------- PYTHON -----------# +# First stage (Builder): +# Install gRPC and all other dependencies +FROM vhiveease/python-slim:latest as imageRotatePythonBuilder +WORKDIR /py +COPY ./benchmarks/image-rotate/python/requirements.txt ./requirements.txt +RUN pip3 install --user -r requirements.txt +COPY ./utils/tracing/python/tracing.py ./ +COPY ./benchmarks/image-rotate/python/server.py ./ +ADD https://raw.githubusercontent.com/vhive-serverless/vSwarm-proto/newfuncs_v0.1.1/proto/image_rotate/image_rotate_pb2_grpc.py ./ +ADD https://raw.githubusercontent.com/vhive-serverless/vSwarm-proto/newfuncs_v0.1.1/proto/image_rotate/image_rotate_pb2.py ./proto/image_rotate/ + +# Second stage (Runner): +FROM vhiveease/python-slim:latest as imageRotatePython +COPY --from=imageRotatePythonBuilder /root/.local /root/.local +COPY --from=imageRotatePythonBuilder /py /app +WORKDIR /app +# ENV PATH=/root/.local/bin:$PATH +ENTRYPOINT [ "python3", "/app/server.py" ] + + +#---------- GoLang -----------# +# First stage (Builder): +FROM vhiveease/golang-builder:latest AS imageRotateGoBuilder +WORKDIR /app/app/ +RUN apt-get install git ca-certificates + +COPY ./utils/tracing/go ../../utils/tracing/go +COPY ./benchmarks/image-rotate/go/go.mod ./ +COPY ./benchmarks/image-rotate/go/go.sum ./ +COPY ./benchmarks/image-rotate/go/server.go ./ + +RUN go mod tidy +RUN CGO_ENABLED=0 GOOS=linux go build -v -o ./server server.go + +# Second stage (Runner): +FROM scratch as imageRotateGo +WORKDIR /app/ +COPY --from=imageRotateGoBuilder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=imageRotateGoBuilder /app/app/server . + +ENTRYPOINT [ "/app/server" ] diff --git a/benchmarks/image-rotate/go/go.mod b/benchmarks/image-rotate/go/go.mod new file mode 100644 index 000000000..d0c1a7f05 --- /dev/null +++ b/benchmarks/image-rotate/go/go.mod @@ -0,0 +1,60 @@ +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +module imagerotate + +go 1.21 + +replace github.com/vhive-serverless/vSwarm/utils/tracing/go => ../../../utils/tracing/go + +require ( + github.com/disintegration/imaging v1.6.2 + github.com/sirupsen/logrus v1.9.3 + github.com/vhive-serverless/vSwarm-proto v0.5.1-0.20240307061327-389a954e629c + github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20231030155054-d3b2e7d0ff16 + go.mongodb.org/mongo-driver v1.15.0 + google.golang.org/grpc v1.61.0 +) + +require ( + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/klauspost/compress v1.16.6 // indirect + github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect + github.com/openzipkin/zipkin-go v0.4.2 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect + go.opentelemetry.io/otel v1.24.0 // indirect + go.opentelemetry.io/otel/exporters/zipkin v1.23.1 // indirect + go.opentelemetry.io/otel/metric v1.24.0 // indirect + go.opentelemetry.io/otel/sdk v1.23.1 // indirect + go.opentelemetry.io/otel/trace v1.24.0 // indirect + golang.org/x/crypto v0.19.0 // indirect + golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect + google.golang.org/protobuf v1.33.0 // indirect +) diff --git a/benchmarks/image-rotate/go/go.sum b/benchmarks/image-rotate/go/go.sum new file mode 100644 index 000000000..7f06ef40b --- /dev/null +++ b/benchmarks/image-rotate/go/go.sum @@ -0,0 +1,108 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= +github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk= +github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA= +github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/vhive-serverless/vSwarm-proto v0.5.1-0.20240307061327-389a954e629c h1:wq+IoG5MqDCLfyGmJ/CusAO34emT5xFT6H4hcM8ZimE= +github.com/vhive-serverless/vSwarm-proto v0.5.1-0.20240307061327-389a954e629c/go.mod h1:bn+lbMm9WqQpU317LJJeF+EwL5K5MAbnN+EogbK3wOU= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc= +go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0= +go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= +go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel/exporters/zipkin v1.23.1 h1:goka4KdsPPpHHQnzp1/XE1wVpk2oQO9RXCOH4MZWSyg= +go.opentelemetry.io/otel/exporters/zipkin v1.23.1/go.mod h1:KXTI1fJdTqRrQlIYgdmF4MnyAbHFWg1z320eOpL53qA= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/sdk v1.23.1 h1:O7JmZw0h76if63LQdsBMKQDWNb5oEcOThG9IrxscV+E= +go.opentelemetry.io/otel/sdk v1.23.1/go.mod h1:LzdEVR5am1uKOOwfBWFef2DCi1nu3SA8XQxx2IerWFk= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA= +google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0= +google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= \ No newline at end of file diff --git a/benchmarks/image-rotate/go/server.go b/benchmarks/image-rotate/go/server.go new file mode 100644 index 000000000..804d126f5 --- /dev/null +++ b/benchmarks/image-rotate/go/server.go @@ -0,0 +1,164 @@ +// MIT License + +// Copyright (c) 2024 EASE lab + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package main + +import ( + "context" + "flag" + "fmt" + "io" + "net" + "os" + "strings" + + "github.com/disintegration/imaging" + log "github.com/sirupsen/logrus" + pb "github.com/vhive-serverless/vSwarm-proto/proto/image_rotate" + tracing "github.com/vhive-serverless/vSwarm/utils/tracing/go" + + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" + + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/gridfs" + "go.mongodb.org/mongo-driver/mongo/options" +) + +var ( + zipkin = flag.String("zipkin", "http://localhost:9411/api/v2/spans", "zipkin url") + address = flag.String("addr", "0.0.0.0:50051", "Address:Port the grpc server is listening to") + default_image = flag.String("default-image", "default.jpg", "Default image to be rotated if empty") + database_address = flag.String("db_addr", "mongodb://image-rotate-database:27017", "Address of the data-base server") +) + +var ( + client *mongo.Client + bucket *gridfs.Bucket +) + +const dbName = "image_db" + +func imageRotate(imgPath string, imgOutPath string) string { + src, err := imaging.Open(imgPath) + if err != nil { + log.Warnf("failed to open image: %v", err) + errorMessage := "go.image_rotate.ImageNotFound.Error:" + err.Error() + return errorMessage + } + rotatedImage := imaging.Rotate90(src) + err = imaging.Save(rotatedImage, imgOutPath) + if err != nil { + log.Warnf("failed to save image: %v", err) + errorMessage := "go.image_rotate.ImageNotSaved.Error:" + err.Error() + return errorMessage + } + message := "go.image_rotate." + imgPath + return message +} + +type server struct { + pb.UnimplementedImageRotateServer +} + +func (s *server) RotateImage(ctx context.Context, in *pb.SendImage) (*pb.GetRotatedImage, error) { + + var imgPath string + var imgOutPath string + if in.GetName() == "" { + imgPath = *default_image + } else { + imgPath = in.GetName() + } + + if _, err := os.Stat(imgPath); err == nil { + } else { + inputImageFile, err := os.Create(imgPath) + if err != nil { + log.Warnf("Error retrieving input image: %v", err) + } + defer inputImageFile.Close() + downloadStream, err := bucket.OpenDownloadStreamByName(imgPath) + if err != nil { + log.Warnf("Error retrieving input image from download stream: %v", err) + } + defer downloadStream.Close() + // _, err = downloadStream.Copy(inputImageFile) + _, err = io.Copy(inputImageFile, downloadStream) + if err != nil { + log.Warnf("Error downloading input image: %v", err) + } + } + + imgOutPath = "rotated_" + imgPath + message := imageRotate(imgPath, imgOutPath) + resp := fmt.Sprintf("fn: ImageRotate | image: %s | return msg: %s | runtime: Go", imgPath, message) + return &pb.GetRotatedImage{Message: resp}, nil +} + +func main() { + val, ok := os.LookupEnv("IS_LAMBDA") + LAMBDA := (ok && (strings.ToLower(val) == "true" || strings.ToLower(val) == "yes" || strings.ToLower(val) == "1")) + if LAMBDA { + } else { + + flag.Parse() + if tracing.IsTracingEnabled() { + log.Printf("Start tracing on : %s\n", *zipkin) + shutdown, err := tracing.InitBasicTracer(*zipkin, "image-rotate function") + if err != nil { + log.Warn(err) + } + defer shutdown() + } + lis, err := net.Listen("tcp", *address) + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + + // var err error + client, err = mongo.Connect(context.Background(), options.Client().ApplyURI(*database_address)) + if err != nil { + log.Fatalf("Error connecting to MongoDB: %v", err) + } + defer client.Disconnect(context.Background()) + bucket, err = gridfs.NewBucket( + client.Database(dbName), + ) + if err != nil { + log.Fatalf("Error using GridFS: %v", err) + } + + log.Printf("Start ImageRotate-go server. Addr: %s\n", *address) + var grpcServer *grpc.Server + if tracing.IsTracingEnabled() { + grpcServer = tracing.GetGRPCServerWithUnaryInterceptor() + } else { + grpcServer = grpc.NewServer() + } + pb.RegisterImageRotateServer(grpcServer, &server{}) + reflection.Register(grpcServer) + if err := grpcServer.Serve(lis); err != nil { + log.Fatalf("failed to serve: %v", err) + } + } +} diff --git a/benchmarks/image-rotate/images/default.jpg b/benchmarks/image-rotate/images/default.jpg new file mode 100644 index 000000000..83912032f Binary files /dev/null and b/benchmarks/image-rotate/images/default.jpg differ diff --git a/benchmarks/image-rotate/images/img1.jpg b/benchmarks/image-rotate/images/img1.jpg new file mode 100644 index 000000000..7fbc9d68a Binary files /dev/null and b/benchmarks/image-rotate/images/img1.jpg differ diff --git a/benchmarks/image-rotate/images/img10.jpg b/benchmarks/image-rotate/images/img10.jpg new file mode 100644 index 000000000..706704f46 Binary files /dev/null and b/benchmarks/image-rotate/images/img10.jpg differ diff --git a/benchmarks/image-rotate/images/img11.jpg b/benchmarks/image-rotate/images/img11.jpg new file mode 100644 index 000000000..cd89ea77a Binary files /dev/null and b/benchmarks/image-rotate/images/img11.jpg differ diff --git a/benchmarks/image-rotate/images/img12.jpg b/benchmarks/image-rotate/images/img12.jpg new file mode 100644 index 000000000..db3ce635b Binary files /dev/null and b/benchmarks/image-rotate/images/img12.jpg differ diff --git a/benchmarks/image-rotate/images/img13.jpg b/benchmarks/image-rotate/images/img13.jpg new file mode 100644 index 000000000..9a29a7878 Binary files /dev/null and b/benchmarks/image-rotate/images/img13.jpg differ diff --git a/benchmarks/image-rotate/images/img15.jpg b/benchmarks/image-rotate/images/img15.jpg new file mode 100644 index 000000000..2a895f355 Binary files /dev/null and b/benchmarks/image-rotate/images/img15.jpg differ diff --git a/benchmarks/image-rotate/images/img16.jpg b/benchmarks/image-rotate/images/img16.jpg new file mode 100644 index 000000000..f18cb7661 Binary files /dev/null and b/benchmarks/image-rotate/images/img16.jpg differ diff --git a/benchmarks/image-rotate/images/img17.jpg b/benchmarks/image-rotate/images/img17.jpg new file mode 100644 index 000000000..aa5f81db3 Binary files /dev/null and b/benchmarks/image-rotate/images/img17.jpg differ diff --git a/benchmarks/image-rotate/images/img2.jpg b/benchmarks/image-rotate/images/img2.jpg new file mode 100644 index 000000000..84d2b92d6 Binary files /dev/null and b/benchmarks/image-rotate/images/img2.jpg differ diff --git a/benchmarks/image-rotate/images/img3.jpg b/benchmarks/image-rotate/images/img3.jpg new file mode 100644 index 000000000..a428014cb Binary files /dev/null and b/benchmarks/image-rotate/images/img3.jpg differ diff --git a/benchmarks/image-rotate/images/img4.jpg b/benchmarks/image-rotate/images/img4.jpg new file mode 100644 index 000000000..d995e5f63 Binary files /dev/null and b/benchmarks/image-rotate/images/img4.jpg differ diff --git a/benchmarks/image-rotate/images/img5.jpg b/benchmarks/image-rotate/images/img5.jpg new file mode 100644 index 000000000..f7f1ec96f Binary files /dev/null and b/benchmarks/image-rotate/images/img5.jpg differ diff --git a/benchmarks/image-rotate/images/img6.jpg b/benchmarks/image-rotate/images/img6.jpg new file mode 100644 index 000000000..3bf0baaf9 Binary files /dev/null and b/benchmarks/image-rotate/images/img6.jpg differ diff --git a/benchmarks/image-rotate/images/img7.jpg b/benchmarks/image-rotate/images/img7.jpg new file mode 100644 index 000000000..9286e5a43 Binary files /dev/null and b/benchmarks/image-rotate/images/img7.jpg differ diff --git a/benchmarks/image-rotate/images/img8.jpg b/benchmarks/image-rotate/images/img8.jpg new file mode 100644 index 000000000..aada4a44d Binary files /dev/null and b/benchmarks/image-rotate/images/img8.jpg differ diff --git a/benchmarks/image-rotate/images/img9.jpg b/benchmarks/image-rotate/images/img9.jpg new file mode 100644 index 000000000..9f1e8b364 Binary files /dev/null and b/benchmarks/image-rotate/images/img9.jpg differ diff --git a/benchmarks/image-rotate/init/go.mod b/benchmarks/image-rotate/init/go.mod new file mode 100644 index 000000000..e8c15b451 --- /dev/null +++ b/benchmarks/image-rotate/init/go.mod @@ -0,0 +1,42 @@ +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +module initdatabase + +go 1.21 + +replace github.com/vhive-serverless/vSwarm/utils/tracing/go => ../../../utils/tracing/go + +require ( + github.com/sirupsen/logrus v1.9.3 + go.mongodb.org/mongo-driver v1.14.0 +) + +require ( + github.com/golang/snappy v0.0.1 // indirect + github.com/klauspost/compress v1.13.6 // indirect + github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect + golang.org/x/crypto v0.17.0 // indirect + golang.org/x/sync v0.1.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect +) diff --git a/benchmarks/image-rotate/init/go.sum b/benchmarks/image-rotate/init/go.sum new file mode 100644 index 000000000..18e4e736f --- /dev/null +++ b/benchmarks/image-rotate/init/go.sum @@ -0,0 +1,66 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80= +go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= \ No newline at end of file diff --git a/benchmarks/image-rotate/init/init-database.go b/benchmarks/image-rotate/init/init-database.go new file mode 100644 index 000000000..787f9499d --- /dev/null +++ b/benchmarks/image-rotate/init/init-database.go @@ -0,0 +1,126 @@ +// MIT License + +// Copyright (c) 2024 EASE lab + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package main + +import ( + "context" + "flag" + "strings" + + "path/filepath" + log "github.com/sirupsen/logrus" + + // "encoding/base64" + "io/ioutil" + + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/mongo/gridfs" +) + +var ( + database_address = flag.String("db_addr", "mongodb://image-rotate-database:27017", "Address of the data-base server") +) + +// Image struct to represent image data +// type Image struct { +// Name string `bson:"name"` +// Data []byte `bson:"data"` +// } + +func main() { + flag.Parse() + + // Connect to MongoDB + client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(*database_address)) + if err != nil { + log.Fatalf("Error connecting to MongoDB: %v", err) + } + defer client.Disconnect(context.Background()) + + dbName := "image_db" + // collection := client.Database(dbName).Collection("images") + + bucket, err := gridfs.NewBucket( + client.Database(dbName), + ) + if err != nil { + log.Fatalf("Error using GridFS: %v", err) + } + + dirPath := "./images" + files, err := ioutil.ReadDir(dirPath) + if err != nil { + log.Fatalf("Error finding files: %v", err) + } + + for _, file := range files { + + if isImageFile(file.Name()) { + + imagePath := filepath.Join(dirPath, file.Name()) + imageFile, err := ioutil.ReadFile(imagePath) + if err != nil { + log.Warn("Error reading file: %v", err) + continue + } + + uploadStream, err := bucket.OpenUploadStream(file.Name()) + defer uploadStream.Close() + if err != nil { + log.Warn("Error creating GridFS upload stream for file %q: %v", imagePath, err) + continue + } + + _, err = uploadStream.Write(imageFile) + if err != nil { + log.Warn("Error uploading file %q to GridFS: %v", imagePath, err) + continue + } + + // base64EncodedImage := base64.StdEncoding.EncodeToString(imageData) + // image := Image { + // Name: file.Name(), + // Data: base64EncodedImage + // } + // _, err = collection.InsertOne(context.Background(), image) + // if err != nil { + // log.Warn("Error inserting image into database:", err) + // continue + // } + + log.Print("Inserted image:", file.Name()) + } + } + +} + +func isImageFile(fileName string) bool { + imageExtensions := []string{".jpg", ".jpeg", ".png"} + for _, ext := range imageExtensions { + if strings.HasSuffix(strings.ToLower(fileName), ext) { + return true + } + } + return false +} diff --git a/benchmarks/image-rotate/python/requirements.txt b/benchmarks/image-rotate/python/requirements.txt new file mode 100644 index 000000000..b86b2eeae --- /dev/null +++ b/benchmarks/image-rotate/python/requirements.txt @@ -0,0 +1,12 @@ +pillow +pymongo +grpcio==1.45.0 +grpcio-tools==1.45.0 +opentelemetry-api==1.3.0 +opentelemetry-exporter-zipkin==1.3.0 +opentelemetry-exporter-zipkin-json==1.3.0 +opentelemetry-exporter-zipkin-proto-http==1.3.0 +opentelemetry-instrumentation==0.22b0 +opentelemetry-instrumentation-grpc==0.22b0 +opentelemetry-sdk==1.3.0 +opentelemetry-semantic-conventions==0.22b0 diff --git a/benchmarks/image-rotate/python/server.py b/benchmarks/image-rotate/python/server.py new file mode 100644 index 000000000..0097930ae --- /dev/null +++ b/benchmarks/image-rotate/python/server.py @@ -0,0 +1,95 @@ +import os +import sys + +import tracing +from PIL import Image, ImageOps, ImageFilter + +from pymongo import MongoClient +import gridfs + +LAMBDA = os.environ.get('IS_LAMBDA', 'no').lower() in ['true', 'yes', '1'] + +# if LAMBDA is set, then ignore + +if not LAMBDA: + import grpc + import argparse + + from proto.image_rotate import image_rotate_pb2 + import image_rotate_pb2_grpc + + from concurrent import futures + + parser = argparse.ArgumentParser() + parser.add_argument("-a", "--addr", dest="addr", default="0.0.0.0", help="IP address") + parser.add_argument("-p", "--port", dest="port", default="50051", help="serve port") + parser.add_argument("-zipkin", "--zipkin", dest="url", default="http://0.0.0.0:9411/api/v2/spans", help="Zipkin endpoint url") + parser.add_argument("--default_image", default="default.jpg", help="Default image to be rotated if empty") + parser.add_argument("--db_addr", default="mongodb://image-rotate-database:27017", help="Address of the data-base server") + + args = parser.parse_args() + +db_name = "image_db" +client = MongoClient(args.db_addr) +db = client[db_name] + +if tracing.IsTracingEnabled(): + tracing.initTracer("image-rotate-python", url=args.url) + tracing.grpcInstrumentClient() + tracing.grpcInstrumentServer() + + +def ImageRotateFunction(image_path): + try: + img = Image.open(image_path) + img = img.filter(ImageFilter.BLUR) + img = img.filter(ImageFilter.MinFilter) + img = img.filter(ImageFilter.EDGE_ENHANCE_MORE) + img = img.filter(ImageFilter.SHARPEN) + img = img.transpose(Image.ROTATE_90) + return f"python.image_rotate.{image_path}" + except Exception as e: + return f"python.image_rotate.ImageNotFound.Error:{e}" + +if not LAMBDA: + class ImageRotate(image_rotate_pb2_grpc.ImageRotateServicer): + def RotateImage(self, request, context): + + if request.name == "": + imagename = f"{args.default_image}" + else: + imagename = f"{request.name}" + + try: + with open(imagename): + pass + except FileNotFoundError: + try: + fs = gridfs.GridFS(db) + image_file_data = fs.find_one({"filename": imagename}) + if image_file_data: + with open(imagename, "wb") as file: + file.write(image_file_data.read()) + else: + msg = f"fn: ImageRotate | image: {imagename} | Error: ImageNotFound in GridFS | runtime: Python" + return image_rotate_pb2.GetRotatedImage(message=msg) + except Exception as e: + msg = f"fn: ImageRotate | image: {imagename} | Error: {e} | runtime: Python" + return image_rotate_pb2.GetRotatedImage(message=msg) + + with tracing.Span("Image Rotate"): + return_msg = ImageRotateFunction(imagename) + msg = f"fn: ImageRotate | image: {imagename} | return msg: {return_msg} | runtime: Python" + return image_rotate_pb2.GetRotatedImage(message=msg) + +def serve(): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) + image_rotate_pb2_grpc.add_ImageRotateServicer_to_server(ImageRotate(), server) + address = (args.addr + ":" + args.port) + server.add_insecure_port(address) + print("Start ImageRotate-python server. Addr: " + address) + server.start() + server.wait_for_termination() + +if __name__ == '__main__': + serve() diff --git a/benchmarks/image-rotate/yamls/docker-compose/dc-image-rotate-go.yaml b/benchmarks/image-rotate/yamls/docker-compose/dc-image-rotate-go.yaml new file mode 100644 index 000000000..3efb63ec3 --- /dev/null +++ b/benchmarks/image-rotate/yamls/docker-compose/dc-image-rotate-go.yaml @@ -0,0 +1,62 @@ +# MIT License + +# Copyright (c) 2024 EASE lab + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +version: "3.3" +services: + image-rotate-go: + image: vhiveease/image-rotate-go:latest + container_name: image-rotate-go + entrypoint: + - /app/server + - --addr=0.0.0.0:50051 + - --db_addr=mongodb://image-rotate-database:27017 + ports: + - target: 50051 + depends_on: + - image-rotate-database + - init-image-rotate-database + image-rotate-database: + image: vhiveease/mongodb + container_name: image-rotate-database + init-image-rotate-database: + image: vhiveease/image-rotate-init-database:latest + container_name: init-image-rotate-database + entrypoint: + - /app/init-database + - --db_addr=mongodb://image-rotate-database:27017 + restart: "no" + depends_on: + - image-rotate-database + relay: + image: vhiveease/relay:latest + entrypoint: + - /app/server + - --addr=0.0.0.0:50000 + - --function-endpoint-url=image-rotate-go + - --function-endpoint-port=50051 + - --function-name=image-rotate-go + - --value=default.jpg + ports: + - published: 50000 + target: 50000 + depends_on: + - image-rotate-go \ No newline at end of file diff --git a/benchmarks/image-rotate/yamls/docker-compose/dc-image-rotate-python.yaml b/benchmarks/image-rotate/yamls/docker-compose/dc-image-rotate-python.yaml new file mode 100644 index 000000000..4006b5232 --- /dev/null +++ b/benchmarks/image-rotate/yamls/docker-compose/dc-image-rotate-python.yaml @@ -0,0 +1,67 @@ +# MIT License + +# Copyright (c) 2024 EASE lab + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +version: "3.3" +services: + image-rotate-python: + image: vhiveease/image-rotate-python:latest + container_name: image-rotate-python + entrypoint: + - python + - /app/server.py + - --addr=0.0.0.0 + - --port=50051 + - --db_addr=mongodb://image-rotate-database:27017 + ports: + - target: 50051 + depends_on: + - image-rotate-database + - init-image-rotate-database + + image-rotate-database: + image: vhiveease/mongodb + container_name: image-rotate-database + + init-image-rotate-database: + image: vhiveease/image-rotate-init-database:latest + container_name: init-image-rotate-database + entrypoint: + - /app/init-database + - --db_addr=mongodb://image-rotate-database:27017 + restart: "no" + depends_on: + - image-rotate-database + + relay: + image: vhiveease/relay:latest + entrypoint: + - /app/server + - --addr=0.0.0.0:50000 + - --function-endpoint-url=image-rotate-python + - --function-endpoint-port=50051 + - --function-name=image-rotate-python + - --value=default.jpg + ports: + - published: 50000 + target: 50000 + depends_on: + - image-rotate-python \ No newline at end of file diff --git a/benchmarks/image-rotate/yamls/knative/image-rotate-database.yaml b/benchmarks/image-rotate/yamls/knative/image-rotate-database.yaml new file mode 100644 index 000000000..618f2ab4a --- /dev/null +++ b/benchmarks/image-rotate/yamls/knative/image-rotate-database.yaml @@ -0,0 +1,74 @@ +# MIT License + +# Copyright (c) 2024 EASE lab + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +## Database ---------- +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: image-rotate-database + namespace: default +spec: + selector: + matchLabels: + app: image-rotate-database + template: + metadata: + labels: + app: image-rotate-database + spec: + containers: + - name: database + image: docker.io/vhiveease/mongodb + ports: + - containerPort: 27017 + +--- +apiVersion: v1 +kind: Service +metadata: + name: image-rotate-database + namespace: default +spec: + type: ClusterIP + selector: + app: image-rotate-database + ports: + - name: database + port: 27017 + targetPort: 27017 + +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: init-image-rotate-database +spec: + template: + spec: + containers: + - name: init-image-rotate-database + image: docker.io/vhiveease/image-rotate-init-database:latest + args: + - --db_addr=mongodb://image-rotate-database:27017 + restartPolicy: Never \ No newline at end of file diff --git a/benchmarks/image-rotate/yamls/knative/kn-image-rotate-go.yaml b/benchmarks/image-rotate/yamls/knative/kn-image-rotate-go.yaml new file mode 100644 index 000000000..0e3288ab2 --- /dev/null +++ b/benchmarks/image-rotate/yamls/knative/kn-image-rotate-go.yaml @@ -0,0 +1,46 @@ +# MIT License + +# Copyright (c) 2024 EASE lab + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: image-rotate-go + namespace: default +spec: + template: + spec: + containers: + - image: docker.io/vhiveease/relay:latest + ports: + - name: h2c + containerPort: 50000 + args: + - --addr=0.0.0.0:50000 + - --function-endpoint-url=0.0.0.0 + - --function-endpoint-port=50051 + - --function-name=image-rotate-go + - --value=img10.jpg + - --profile-function=true + - image: docker.io/vhiveease/image-rotate-go:latest + args: + - --addr=0.0.0.0:50051 + - --db_addr=mongodb://image-rotate-database:27017 diff --git a/benchmarks/image-rotate/yamls/knative/kn-image-rotate-python.yaml b/benchmarks/image-rotate/yamls/knative/kn-image-rotate-python.yaml new file mode 100644 index 000000000..311cf9b81 --- /dev/null +++ b/benchmarks/image-rotate/yamls/knative/kn-image-rotate-python.yaml @@ -0,0 +1,47 @@ +# MIT License + +# Copyright (c) 2024 EASE lab + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: image-rotate-python + namespace: default +spec: + template: + spec: + containers: + - image: docker.io/vhiveease/relay:latest + ports: + - name: h2c + containerPort: 50000 + args: + - --addr=0.0.0.0:50000 + - --function-endpoint-url=0.0.0.0 + - --function-endpoint-port=50051 + - --function-name=image-rotate-python + - --value=img4.jpg + - --profile-function=true + - image: docker.io/vhiveease/image-rotate-python:latest + args: + - --addr=0.0.0.0 + - --port=50051 + - --db_addr=mongodb://image-rotate-database:27017 diff --git a/tools/relay/go.mod b/tools/relay/go.mod index 03f747132..c3d810598 100644 --- a/tools/relay/go.mod +++ b/tools/relay/go.mod @@ -6,9 +6,9 @@ replace github.com/vhive-serverless/vSwarm/utils/tracing/go => ../../utils/traci require ( github.com/sirupsen/logrus v1.9.3 - github.com/vhive-serverless/vSwarm-proto v0.5.2 - github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20240422181019-5b1711d87c5d - google.golang.org/grpc v1.63.2 + github.com/vhive-serverless/vSwarm-proto v0.5.6-0.20240719123414-e868a3385d9b + github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20240715172541-1edab0214c9d + google.golang.org/grpc v1.65.0 ) require ( @@ -24,6 +24,6 @@ require ( golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434 // indirect - google.golang.org/protobuf v1.34.1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect + google.golang.org/protobuf v1.34.2 // indirect ) diff --git a/tools/relay/go.sum b/tools/relay/go.sum index 24eb02bd6..eded5fda2 100644 --- a/tools/relay/go.sum +++ b/tools/relay/go.sum @@ -6,8 +6,6 @@ github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg= @@ -20,8 +18,12 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/vhive-serverless/vSwarm-proto v0.5.2 h1:PlGF53h7chTKMY3F1P8TEAAeaUc6FxKf56ykDfSJGpk= -github.com/vhive-serverless/vSwarm-proto v0.5.2/go.mod h1:mqNOaNPkghDe3Fszx1KIvkTmwaU9y+n+YlOQVMLQ0L8= +github.com/vhive-serverless/vSwarm-proto v0.5.6-0.20240719075027-5a708624ffbe h1:7ZNSPcswCC2lOsuz5fkpxQ1xN1/Y7m/sXxQQI+8zylI= +github.com/vhive-serverless/vSwarm-proto v0.5.6-0.20240719075027-5a708624ffbe/go.mod h1:XYZTSOP5iQ+BtKMWek5DEP0+TFpaI7RNRQwYJ52f6h0= +github.com/vhive-serverless/vSwarm-proto v0.5.6-0.20240719121158-3a4c1ddf202b h1:WlzhsT8UzF1DW+P3fdnHKNm9Hq8PrYN49txaqfmUpAA= +github.com/vhive-serverless/vSwarm-proto v0.5.6-0.20240719121158-3a4c1ddf202b/go.mod h1:qrSDWXheQpTLhj0mKn3deujXT/rB9qr6sQZ5qXUYVZA= +github.com/vhive-serverless/vSwarm-proto v0.5.6-0.20240719123414-e868a3385d9b h1:3yexzahPLvtcve1zQsV4OlyKEynbi6R/2SE6IVgA5OE= +github.com/vhive-serverless/vSwarm-proto v0.5.6-0.20240719123414-e868a3385d9b/go.mod h1:qrSDWXheQpTLhj0mKn3deujXT/rB9qr6sQZ5qXUYVZA= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 h1:A3SayB3rNyt+1S6qpI9mHPkeHTZbD7XILEqWnYZb2l0= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0/go.mod h1:27iA5uvhuRNmalO+iEUdVn5ZMj2qy10Mm+XRIpRmyuU= go.opentelemetry.io/otel v1.26.0 h1:LQwgL5s/1W7YiiRwxf03QGnWLb2HW4pLiAhaA5cZXBs= @@ -41,12 +43,12 @@ golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434 h1:umK/Ey0QEzurTNlsV3R+MfxHAb78HCEX/IkuR+zH4WQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM= -google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= -google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/tools/relay/server b/tools/relay/server deleted file mode 100755 index 05a1c6460..000000000 Binary files a/tools/relay/server and /dev/null differ diff --git a/tools/relay/server.go b/tools/relay/server.go index 9e7f331ad..9a400e2cd 100644 --- a/tools/relay/server.go +++ b/tools/relay/server.go @@ -28,6 +28,8 @@ import ( "fmt" "net" "os" + "strconv" + "time" pb "github.com/vhive-serverless/vSwarm-proto/proto/helloworld" @@ -61,6 +63,7 @@ var ( value = flag.String("value", "helloWorld", "String input to pass to benchmark") functionMethod = flag.String("function-method", "default", "Which method of benchmark to invoke") verbose = flag.Bool("verbose", false, "Enable verbose log printing") + profileFunction = flag.Bool("profile-function", false, "Enable latency measurements of the function") // Client grpcClient grpcClients.GrpcClient @@ -155,8 +158,21 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe // Create new packet pkt := inputGenerator.Next() log.Debugf("Send to func: %s\n", pkt) + startTime := time.Now() reply, err := grpcClient.Request(ctx, pkt) - log.Debugf("Recv from func: %s\n", reply) + endTime := time.Now() + elapsedMicroseconds := int64(endTime.Sub(startTime).Microseconds()) - return &pb.HelloReply{Message: reply}, err + var finalReply string + + if *profileFunction { + log.Debugf("Recv from func: %s dur: %d\n", reply, elapsedMicroseconds) + elapsedTime := strconv.FormatInt(elapsedMicroseconds, 10) + finalReply = reply + " | " + elapsedTime + } else { + log.Debugf("Recv from func: %s\n", reply) + finalReply = reply + } + + return &pb.HelloReply{Message: finalReply}, err }