An application to demonstrate caching and locust tests
The purpose is to demonstrate and introduce caching with redis on the view and updating the database every 30secs with the correct data so that every user can access the data that's no older than 1 min.
- Since NGINX/Postgres is not optimised, the system can currently take on only a default value of 300 people
- Redis is programmed to invalidate it's cache every 45 secs.
- Celery scheduled task runs every 30 secs
- Use docker, and install docker first :)
docker-compose up
will start redis, django and nginx- You can access the movies list using
http://127.0.0.1:8000/movies/
- A basic HTML UI will be waiting for you, Django templating is used.
My favorite bit 🎉
pip install locust
cd locust/
- Start locust by
locust
- nginx/web/redis should be up and running
- Log in to
http://127.0.0.1:8089/
and set the number of users to 300 and the relative fields. - Let locust do it's thing
You can view the finite resources and the results in locust_report.html
- Should optimise the nginx conf
- Should tweak postgres as well (I tried pgbouncer, did not work for some reason...)
- But considering that my computer is finite, I guess this is a nice solution, but ofc not the final optimised version
- The Celery + Postgres bit might be a bit over engineering but still went with it