CherryPy performance testing on Python 2.7 / 3.9 / 3.10 by Locust!

Created:22-04-17 17:30    Updated:23-01-28 22:56


I am both a fan of Python and its web framework CherryPy.

Recently I upgraded one of my CherryPy-powered sites from Python 2.7 / CherryPy 17.4.2 to Python 3.X / CherryPy 18.6.1. Using the 2to3 tool, the code migration from Python 2 to 3 was surprisingly easy, I only need to manually change a very small portion of the code.

After upgrading, I was curious if the migration would have any performance impacts, so I used the Python powered Locust load testing tool (I am impress by it!), to do a load testing on my test machine (Surface Go 2 - Intel Core M3 8100Y (1.10GHz) 8GB Memory), which on the same time, runs 3 instances of my CherryPy testing site:

  • Port 84: CherryPy 18.6.1 on Python 3.10
  • Port 83: CherryPy 18.6.1 on Python 3.9
  • Port 81: CherryPy 17.4.2 on Python 2.7

The testing results are all good news! I was quite surprised that the speed difference was so huge between Python 2.7 instance and Python 3.9 instance, and Python 3.10 instance was even a little bit better!

Show Picture

** Concurrency: 150 users **

  • Run #1 - Left: CherryPy 18.6.1 on Python 3.10 ~94RPS, ~68ms response time, after stable
  • Run #2 - Mid: CherryPy 18.6.1 on Python 3.9 ~87RPS, ~160ms response time, after stable
  • Run #3 - Right: CherryPy 17.4.2 on Python 2.7 ~40RPS, ~2.1s response time, after stable, and with many ConnectionRefusedErrors at first

It's worth mentioning, that the tested site is not a "hello world" project, it's a small real-world site that reads contents from SQLite backend database, and renders pages by the Jinja2 template engine, cookies and sessions are also used, after processing the outputed page size loaded by Locust were about 30 Kb in average. Also, consider it's running on a dual core Surface, I'm quite happy with the performance.

P.S. Why I am still a fan of the old CherryPy instead of more popular micro frameworks like Flask and FastAPI? Because IMHO, if it is used in production, Flask or FastAPI needs another production-ready WSGI HTTP Server, the officially recommended one is gunicorn, but it's only available under UNIX, while I am a mostly windows user... CherryPy / Cheroot can also be this WSGI server, but why shouldn't I use cherrypy as an All-in-One solution?

***See also: ***

Python 3.10, 3.9, 3.8, 3.7 performance vs 2.7


An Online Pomodoro Timer is here