From 726cde7159b6888b6ce838afd8c69cb6cc220a06 Mon Sep 17 00:00:00 2001 From: Lakshman Date: Sat, 20 Jul 2024 14:26:39 -0600 Subject: [PATCH] Added files for video-processing benchmark. Signed-off-by: Lakshmanan --- .gitattributes | 6 + .github/workflows/e2e-video-processing.yml | 7 +- benchmarks/video-processing/Makefile | 49 ++++++++ benchmarks/video-processing/docker/Dockerfile | 64 ++++++++++ benchmarks/video-processing/init/go.mod | 42 +++++++ benchmarks/video-processing/init/go.sum | 66 ++++++++++ .../video-processing/init/init-database.go | 115 ++++++++++++++++++ .../video-processing/python/requirements.txt | 12 ++ benchmarks/video-processing/python/server.py | 102 ++++++++++++++++ .../video-processing/videos/default.mp4 | 3 + benchmarks/video-processing/videos/video1.mp4 | 3 + benchmarks/video-processing/videos/video2.mp4 | 3 + benchmarks/video-processing/videos/video3.mp4 | 3 + benchmarks/video-processing/videos/video4.mp4 | 3 + .../dc-video-processing-python.yaml | 64 ++++++++++ .../knative/kn-video-processing-python.yaml | 48 ++++++++ .../knative/video-processing-database.yaml | 74 +++++++++++ 17 files changed, 661 insertions(+), 3 deletions(-) create mode 100644 benchmarks/video-processing/Makefile create mode 100644 benchmarks/video-processing/docker/Dockerfile create mode 100644 benchmarks/video-processing/init/go.mod create mode 100644 benchmarks/video-processing/init/go.sum create mode 100644 benchmarks/video-processing/init/init-database.go create mode 100644 benchmarks/video-processing/python/requirements.txt create mode 100644 benchmarks/video-processing/python/server.py create mode 100644 benchmarks/video-processing/videos/default.mp4 create mode 100644 benchmarks/video-processing/videos/video1.mp4 create mode 100644 benchmarks/video-processing/videos/video2.mp4 create mode 100644 benchmarks/video-processing/videos/video3.mp4 create mode 100644 benchmarks/video-processing/videos/video4.mp4 create mode 100644 benchmarks/video-processing/yamls/docker-compose/dc-video-processing-python.yaml create mode 100644 benchmarks/video-processing/yamls/knative/kn-video-processing-python.yaml create mode 100644 benchmarks/video-processing/yamls/knative/video-processing-database.yaml diff --git a/.gitattributes b/.gitattributes index e75abb6eb..199fea007 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17,3 +17,9 @@ benchmarks/image-rotate/images/img10.jpg filter=lfs diff=lfs merge=lfs -text benchmarks/image-rotate/images/img16.jpg filter=lfs diff=lfs merge=lfs -text benchmarks/image-rotate/images/img17.jpg filter=lfs diff=lfs merge=lfs -text benchmarks/image-rotate/images/img3.jpg filter=lfs diff=lfs merge=lfs -text +benchmarks/video-processing/*.mp4 filter=lfs diff=lfs merge=lfs -text +benchmarks/video-processing/videos/default.mp4 filter=lfs diff=lfs merge=lfs -text +benchmarks/video-processing/videos/video1.mp4 filter=lfs diff=lfs merge=lfs -text +benchmarks/video-processing/videos/video2.mp4 filter=lfs diff=lfs merge=lfs -text +benchmarks/video-processing/videos/video3.mp4 filter=lfs diff=lfs merge=lfs -text +benchmarks/video-processing/videos/video4.mp4 filter=lfs diff=lfs merge=lfs -text diff --git a/.github/workflows/e2e-video-processing.yml b/.github/workflows/e2e-video-processing.yml index 18bcf88a1..e2449a71f 100644 --- a/.github/workflows/e2e-video-processing.yml +++ b/.github/workflows/e2e-video-processing.yml @@ -183,10 +183,11 @@ jobs: if: ${{ always() }} run: | set -x - container_list=$(kubectl get pods -n default -o jsonpath="{.items[*].spec.containers[*].name}") - for container_name in $container_list + + pod_list=$(kubectl get pods -n default -o jsonpath="{.items[*].name}") + for pod in $pod_list do - kubectl logs -n default -c $container_name -l serving.knative.dev/service=${{ matrix.service }} + kubectl logs $pod done - name: Print logs from database diff --git a/benchmarks/video-processing/Makefile b/benchmarks/video-processing/Makefile new file mode 100644 index 000000000..1db1f91e9 --- /dev/null +++ b/benchmarks/video-processing/Makefile @@ -0,0 +1,49 @@ +# 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: video-processing-python init-database + +video-processing-python: docker/Dockerfile python/server.py python/requirements.txt videos/default.mp4 + DOCKER_BUILDKIT=1 docker build \ + --tag vhiveease/video-processing-python:latest \ + --target videoProcessingPython \ + -f docker/Dockerfile \ + $(ROOT) --load + +init-database: docker/Dockerfile init/init-database.go videos/default.mp4 + DOCKER_BUILDKIT=1 docker build \ + --tag vhiveease/video-processing-init-database:latest \ + --target databaseInit \ + -f docker/Dockerfile \ + $(ROOT) --load + +## Push images +push: + docker push docker.io/vhiveease/video-processing-python:latest + docker push docker.io/vhiveease/video-processing-init-database:latest + +## Pull images from docker hub +pull: + docker pull docker.io/vhiveease/video-processing-python:latest + docker pull docker.io/vhiveease/video-processing-init-database:latest diff --git a/benchmarks/video-processing/docker/Dockerfile b/benchmarks/video-processing/docker/Dockerfile new file mode 100644 index 000000000..0107f5ea1 --- /dev/null +++ b/benchmarks/video-processing/docker/Dockerfile @@ -0,0 +1,64 @@ +# 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/video-processing/init/go.mod ./ +COPY ./benchmarks/video-processing/init/go.sum ./ +COPY ./benchmarks/video-processing/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/video-processing/videos/ ./videos + +ENTRYPOINT [ "/app/init-database" ] + + +#---------- PYTHON -----------# +# First stage (Builder): +# Install gRPC and all other dependencies +FROM vhiveease/python-slim:latest as videoProcessingPythonBuilder +WORKDIR /py +COPY ./benchmarks/video-processing/python/requirements.txt ./requirements.txt +RUN pip3 install --user -r requirements.txt +COPY ./utils/tracing/python/tracing.py ./ +COPY ./benchmarks/video-processing/python/server.py ./ +ADD https://raw.githubusercontent.com/vhive-serverless/vSwarm-proto/newfuncs_v0.1.4/proto/video_processing/video_processing_pb2_grpc.py ./ +ADD https://raw.githubusercontent.com/vhive-serverless/vSwarm-proto/newfuncs_v0.1.4/proto/video_processing/video_processing_pb2.py ./proto/video_processing/ + +# Second stage (Runner): +FROM vhiveease/python-slim:latest as videoProcessingPython +COPY --from=videoProcessingPythonBuilder /root/.local /root/.local +COPY --from=videoProcessingPythonBuilder /py /app +WORKDIR /app +# ENV PATH=/root/.local/bin:$PATH +ENTRYPOINT [ "python3", "/app/server.py" ] diff --git a/benchmarks/video-processing/init/go.mod b/benchmarks/video-processing/init/go.mod new file mode 100644 index 000000000..3ff386480 --- /dev/null +++ b/benchmarks/video-processing/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 +) \ No newline at end of file diff --git a/benchmarks/video-processing/init/go.sum b/benchmarks/video-processing/init/go.sum new file mode 100644 index 000000000..18e4e736f --- /dev/null +++ b/benchmarks/video-processing/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/video-processing/init/init-database.go b/benchmarks/video-processing/init/init-database.go new file mode 100644 index 000000000..52d124d8a --- /dev/null +++ b/benchmarks/video-processing/init/init-database.go @@ -0,0 +1,115 @@ +// 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" + + "os" + + "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://video-processing-database:27017", "Address of the data-base server") +) + +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 func() { + if err = client.Disconnect(context.Background()); err != nil { + log.Fatalf("Disconnect error: %v", err) + } + }() + + dbName := "video_db" + + bucket, err := gridfs.NewBucket( + client.Database(dbName), + ) + if err != nil { + log.Fatalf("Error using GridFS: %v", err) + } + + dirPath := "./videos" + files, err := os.ReadDir(dirPath) + if err != nil { + log.Fatalf("Error finding files: %v", err) + } + + for _, file := range files { + + if isVideoFile(file.Name()) { + + videoPath := filepath.Join(dirPath, file.Name()) + videoFile, err := os.ReadFile(videoPath) + if err != nil { + log.Warnf("Error reading file: %v", err) + continue + } + + uploadStream, err := bucket.OpenUploadStream(file.Name()) + defer func() { + if err = uploadStream.Close(); err != nil { + log.Fatalf("Disconnect error: %v", err) + } + }() + if err != nil { + log.Warnf("Error creating GridFS upload stream for file %q: %v", videoPath, err) + continue + } + + _, err = uploadStream.Write(videoFile) + if err != nil { + log.Warnf("Error uploading file %q to GridFS: %v", videoPath, err) + continue + } + log.Print("Inserted video:", file.Name()) + } + } + +} + +func isVideoFile(fileName string) bool { + videoExtensions := []string{".mp4"} + for _, ext := range videoExtensions { + if strings.HasSuffix(strings.ToLower(fileName), ext) { + return true + } + } + return false +} + diff --git a/benchmarks/video-processing/python/requirements.txt b/benchmarks/video-processing/python/requirements.txt new file mode 100644 index 000000000..ab5ef1a1c --- /dev/null +++ b/benchmarks/video-processing/python/requirements.txt @@ -0,0 +1,12 @@ +opencv-python-headless +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 \ No newline at end of file diff --git a/benchmarks/video-processing/python/server.py b/benchmarks/video-processing/python/server.py new file mode 100644 index 000000000..ea12ca4ac --- /dev/null +++ b/benchmarks/video-processing/python/server.py @@ -0,0 +1,102 @@ +import os +import sys + +import tracing +import cv2 + +from pymongo import MongoClient +import gridfs + +import grpc +import argparse + +from proto.video_processing import video_processing_pb2 +import video_processing_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_video", default="default.mp4", help="Default video to be converted to grayscale if empty") +parser.add_argument("--num_frames", default=5, help="Number of frames to be considered") +parser.add_argument("--db_addr", default="mongodb://video-processing-database:27017", help="Address of the data-base server") + +args = parser.parse_args() +args.num_frames = int(args.num_frames) + +db_name = "video_db" +client = MongoClient(args.db_addr) +db = client[db_name] + +if tracing.IsTracingEnabled(): + tracing.initTracer("video-processing-python", url=args.url) + tracing.grpcInstrumentClient() + tracing.grpcInstrumentServer() + + +def ConvertToGrayscaleFunction(video_path, output_video_path): + try: + video = cv2.VideoCapture(video_path) + + width = int(video.get(3)) + height = int(video.get(4)) + fourcc = cv2.VideoWriter_fourcc(*'mp4v') + result_video = cv2.VideoWriter(output_video_path, fourcc, 20.0, (width, height)) + + for _ in range(args.num_frames): + success, frame = video.read() + if not success: break + gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + result_video.write(gray_frame) + + video.release() + result_video.release() + return f"python.video_processing.{video_path}" + except Exception as e: + return f"python.video_processing.VideoProcessingFailed.Error:{e}" + +class VideoProcessing(video_processing_pb2_grpc.VideoProcessingServicer): + def ConvertToGrayscale(self, request, context): + + if request.name == "": + video_name = f"{args.default_video}" + output_video_name = f"output-{args.default_video}" + else: + video_name = f"{request.name}" + output_video_name = f"output-{request.name}" + + try: + with open(video_name): + pass + except FileNotFoundError: + try: + fs = gridfs.GridFS(db) + video_file_data = fs.find_one({"filename": video_name}) + if video_file_data: + with open(video_name, "wb") as file: + file.write(video_file_data.read()) + else: + msg = f"fn: VideoProcessing | video: {video_name} | Error: VideoNotFound in GridFS | runtime: Python" + return video_processing_pb2.GetGrayscaleVideo(message=msg) + except Exception as e: + msg = f"fn: VideoProcessing | video: {video_name} | Error: {e} | runtime: Python" + return video_processing_pb2.GetGrayscaleVideo(message=msg) + + with tracing.Span("Video Processing"): + return_msg = ConvertToGrayscaleFunction(video_name, output_video_name) + msg = f"fn: VideoProcessing | video: {video_name} | return msg: {return_msg} | runtime: Python" + return video_processing_pb2.GetGrayscaleVideo(message=msg) + +def serve(): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) + video_processing_pb2_grpc.add_VideoProcessingServicer_to_server(VideoProcessing(), server) + address = (args.addr + ":" + args.port) + server.add_insecure_port(address) + print("Start VideoProcessing-python server. Addr: " + address) + server.start() + server.wait_for_termination() + +if __name__ == '__main__': + serve() \ No newline at end of file diff --git a/benchmarks/video-processing/videos/default.mp4 b/benchmarks/video-processing/videos/default.mp4 new file mode 100644 index 000000000..07e42504d --- /dev/null +++ b/benchmarks/video-processing/videos/default.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7b37d93e4a44ed8ab05059b88bc9355b2c85a318d3922b0bdf2b7b63fb9fe80 +size 93421435 diff --git a/benchmarks/video-processing/videos/video1.mp4 b/benchmarks/video-processing/videos/video1.mp4 new file mode 100644 index 000000000..1ad0f610c --- /dev/null +++ b/benchmarks/video-processing/videos/video1.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d803c1d6384c4a0bafef6768f0f65b8d2abd831da1e46c37dffe6731369a78d +size 3159250 diff --git a/benchmarks/video-processing/videos/video2.mp4 b/benchmarks/video-processing/videos/video2.mp4 new file mode 100644 index 000000000..7b73ccbf7 --- /dev/null +++ b/benchmarks/video-processing/videos/video2.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a56d1581dc363a154179e5ed7545d046d4cc617239ab43319f2bbf593990dde6 +size 13026021 diff --git a/benchmarks/video-processing/videos/video3.mp4 b/benchmarks/video-processing/videos/video3.mp4 new file mode 100644 index 000000000..bcf340b40 --- /dev/null +++ b/benchmarks/video-processing/videos/video3.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e65ae71bc5cf8907a50c3a354b24f24b099e9414656df8eb73f0c6d0f643040f +size 38588588 diff --git a/benchmarks/video-processing/videos/video4.mp4 b/benchmarks/video-processing/videos/video4.mp4 new file mode 100644 index 000000000..07e42504d --- /dev/null +++ b/benchmarks/video-processing/videos/video4.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7b37d93e4a44ed8ab05059b88bc9355b2c85a318d3922b0bdf2b7b63fb9fe80 +size 93421435 diff --git a/benchmarks/video-processing/yamls/docker-compose/dc-video-processing-python.yaml b/benchmarks/video-processing/yamls/docker-compose/dc-video-processing-python.yaml new file mode 100644 index 000000000..f674b3324 --- /dev/null +++ b/benchmarks/video-processing/yamls/docker-compose/dc-video-processing-python.yaml @@ -0,0 +1,64 @@ +# 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: + video-processing-python: + image: vhiveease/video-processing-python:latest + container_name: video-processing-python + entrypoint: + - python + - /app/server.py + - --addr=0.0.0.0 + - --port=50051 + - --db_addr=mongodb://video-processing-database:27017 + - --default_video=default.mp4 + - --num_frames=10 + ports: + - target: 50051 + depends_on: + - video-processing-database + - init-video-processing-database + video-processing-database: + image: vhiveease/mongodb + container_name: video-processing-database + init-video-processing-database: + image: vhiveease/video-processing-init-database:latest + container_name: init-video-processing-database + entrypoint: + - /app/init-database + - --db_addr=mongodb://video-processing-database:27017 + restart: "no" + depends_on: + - video-processing-database + relay: + image: vhiveease/relay-latency:latest + entrypoint: + - /app/server + - --addr=0.0.0.0:50000 + - --function-endpoint-url=video-processing-python + - --function-endpoint-port=50051 + - --function-name=video-processing-python + - --value=video3.mp4 + ports: + - published: 50000 + target: 50000 \ No newline at end of file diff --git a/benchmarks/video-processing/yamls/knative/kn-video-processing-python.yaml b/benchmarks/video-processing/yamls/knative/kn-video-processing-python.yaml new file mode 100644 index 000000000..0ced01b36 --- /dev/null +++ b/benchmarks/video-processing/yamls/knative/kn-video-processing-python.yaml @@ -0,0 +1,48 @@ +# 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: video-processing-python + namespace: default +spec: + template: + spec: + containers: + - image: docker.io/vhiveease/relay-latency: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=video-processing-python + - --value=video3.mp4 + - image: docker.io/vhiveease/video-processing-python:latest + args: + - --addr=0.0.0.0 + - --port=50051 + - --db_addr=mongodb://video-processing-database:27017 + - --default_video=default.mp4 + - --num_frames=10 diff --git a/benchmarks/video-processing/yamls/knative/video-processing-database.yaml b/benchmarks/video-processing/yamls/knative/video-processing-database.yaml new file mode 100644 index 000000000..c2bee1567 --- /dev/null +++ b/benchmarks/video-processing/yamls/knative/video-processing-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: video-processing-database + namespace: default +spec: + selector: + matchLabels: + app: video-processing-database + template: + metadata: + labels: + app: video-processing-database + spec: + containers: + - name: database + image: docker.io/vhiveease/mongodb + ports: + - containerPort: 27017 + +--- +apiVersion: v1 +kind: Service +metadata: + name: video-processing-database + namespace: default +spec: + type: ClusterIP + selector: + app: video-processing-database + ports: + - name: database + port: 27017 + targetPort: 27017 + +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: init-video-processing-database +spec: + template: + spec: + containers: + - name: init-video-processing-database + image: docker.io/vhiveease/video-processing-init-database:latest + args: + - --db_addr=mongodb://video-processing-database:27017 + restartPolicy: Never \ No newline at end of file