danionescu0 / docker-flask-mongodb-example

Uses docker compose with a python flask microservice and MongoDB instance to make a sample application
GNU General Public License v3.0
99 stars 41 forks source link

Test the "random-demo" using pypy #52

Closed danionescu0 closed 3 years ago

danionescu0 commented 3 years ago

If it's faster under load, create a separate Dockerfile and a new docker-compose service image with the pypy version of random demo

use Apache bench for load testing:

ab -n 3000 -c 10 http://localhost:800/random?lower=10&upper=100

neelabalan commented 3 years ago

How can I help with this one?

danionescu0 commented 3 years ago

Sure.

danionescu0 commented 3 years ago

We'll publish the new docker image and results if's get better results in tests > 10% i guess. What do you think?

neelabalan commented 3 years ago

I haven't done this before. I was hoping to get your guidance on doing this or help you do this.

danionescu0 commented 3 years ago

Oh ok, I would start by creating a new docker image from pypy (https://hub.docker.com/_/pypy)

Something like this:

FROM pypy:3 ARG requirements RUN apt-get update RUN apt install git -y WORKDIR /root RUN git clone https://github.com/danionescu0/docker-flask-mongodb-example.git flask-mongodb-example WORKDIR /root/flask-mongodb-example/python RUN pip install -qr $requirements EXPOSE 5000

And place it in a separate folder like docker-python-pypy

Then modify docker-compose to add a new backend:

web-random-pypy:
    build:
        context: ./docker-python-pypy
        args:
            requirements: /root/flask-mongodb-example/python/requirements.txt
    image: web-standard-pypy
    ports:
        - "800:5000"
    entrypoint: /opt/pypy/bin/pypy3 /root/flask-mongodb-example/python/random_demo.py
    depends_on:
        - mongo

Then test then with apachebench under various loads (https://developer.okta.com/blog/2019/10/15/performance-testing-with-apache-bench)

If it performs better for requests per second on your machine (let's say by minumum 10%) the changes will be publish, if not i think there's no need

Do you need extra information ?

neelabalan commented 3 years ago

nope. This is good. I will start working on this. Thank you.

neelabalan commented 3 years ago

results for apache benchmark load testing with changes in docker-compose and Dockerfile.

There is ~38% increase in the request/sec (mean) when using pypy.

danionescu0 commented 3 years ago

That sounds great! I think i'll add a benchmark method to random demo, a method that won't touch the database or disk after you'll make the PR and i think the result will be way better than 38%. Great news you can make the PR and i'll update the readme.md afterwards with the results you've came up with, is it ok ?

neelabalan commented 3 years ago

yes. I will make a PR for the changes in docker-compose and Dockerfile

danionescu0 commented 3 years ago

I've added some documentation and mentioned you in the Readme. Thanks I've also moved the service to a different port due to port collisions.