/pythonMicroframeworks

memory & speed comparison of (bottle cherrypy flask tornado web.py)

Primary LanguagePythonMIT LicenseMIT

pythonMicroframeworks

comparison of (memory & speed of)

  • bottle
  • cherrypy
  • Flask
  • tornado
  • web.py

Each can be started standalone (see test_frameworkname.py), and serves a "Hello World!" to the browser.

Quickstart

Get my (comparison & 5 servers) sourcecode:

git clone https://github.com/drandreaskrueger/pythonMicroframeworks.git
cd pythonMicroframeworks

Dependencies - Prepare machine with tools and python 2.7 pip; and upgrade pip, and install all frameworks:

apt-get update && apt-get install -y git nano sudo python-pip build-essential python-dev
virtualenv env; source env/bin/activate; python --version  # Python 2.7.16 - see issue 1
pip install -U pip && pip install bottle cherrypy Flask tornado web.py psutil requests

Tested on my machine in 2020 on Debian 10 Buster. And 2016 in the cloud, on Debian 8 Digitalocean VPS - bookmark my superb manual how to initialize & install django there. These are the library versions used in 2020:

pip freeze | grep "bottle\|CherryPy\|Flask\|tornado\|web.py"
# bottle==0.12.18, CherryPy==17.4.2, Flask==1.1.2, tornado==5.1.1, web.py==0.51

Start comparison with

python compare.py 

Commandline arguments

If -for hammering- you want more repetitions (per framework) and different timeout (in seconds):

python compare.py 2000
python compare.py 2000 0.5

Results

Put

besides each other in two windows, for now. (ToDo: Everything into one table.)

Strange

Memory measurement via psutil:

  • There is a big discrepancy between rss, and vms on Linux and Windows.
  • To me it looks as if Linux.rss ~= Windows.vms. Strange - but the numbers are too close to not notice that.
  • See psutil tool. Hopefully, psutil 4.0.0 will be more useful. My 3.3.0 does not have memory_full_info() yet.

Main findings

  • Most of my measurements show more memory usage than this 2011 examination - but those were older versions.
  • web.py is slower, especially on Windows, hammering takes ~60% longer as for any of the others.
  • web.py is the first to timeout on Windows.
  • tornado is the first to timeout on Linux.
  • After hammering (2000 requests per framework), the memory usage is higher.
    • for bottle, the effect is < 1%. Bottle seems to have the best memory management.
    • all the other frameworks need considerably more memory after having served 2000 url requests.
    • the effect is stronger on Windows for most of them.
    • for tornado the effect is stronger on Linux - it needs 23% more memory after 2000 url requests.
  • Some of the frameworks are probably really powerful, but also more difficult to understand. And ...

... before my final verdict, I guess I need to sleep. This was ~9 hours of straight coding. After a full working day. :-)

Punchcard

Using my cool new tool, this is a very inaccurate work time estimation:

errors = False, accesstimes = True, granularity = 20, fillsize = 60, ignore = True, omit = False
C:\...\github-drandreaskrueger-pythonMicroframeworks
Found 612 times, of which 335 are unique,
between 2016-03-04 22:21:55,
    and 2016-03-05 15:07:00.

Each 'x' represents a 20 minute block:
2016-03-04|-------------------------------------------------------------------x  xx|
2016-03-05|xxxxx xxxxx   x  xxx xxx  x               xxxx--------------------------|
With 20-minute blocks, the number of hours is approx 8.3

Filling up blocks of size 3, i.e. pauses of approx 60 minutes.

Each 'x' represents a 20 minute block:
2016-03-04|-------------------------------------------------------------------xxxxx|
2016-03-05|xxxxxxxxxxxxxxxxxxxxxxxxxxx               xxxx--------------------------|
With 20-minute blocks, the number of hours is approx 12.0

In this case it works out pretty accurate, it was one long work flow until I collapsed into bed, and slept 4 hours.

You

Suggestion: Migrate all this from Python 2.7.16 to Python 3.x = Solve issue 1. Thanks.

Please help, fork it, improve it, pull request. It was a one-night-hack. Not everything is super-elegant yet. But it works. You can actually include your favorite webframework now, easily.

Please retweet, thx.

Donationware

Very important - If you like this, show it: [BTC] 14EyWS5z8Y5kgwq52D3qeZVor1rUsdNYJy. Thanks, much appreciated.
No Coinbase account yet? Then use my referral, to give me and you 10$ bonus. Oh yes, you can also hire me, part time.