Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which setup is more efficient? Flask with pypy, or Flask with gevent?

Tags:

Both 'pypy' and 'gevent' are supposed to provide high performance. Pypy is supposedly faster than CPython, while gevent is based on co-routines and greenlets, which supposedly makes for a faster web server.

However, they're not compatible with each other.

I'm wondering which setup is more efficient (in terms of speed/performance):

  • The builtin Flask server running on pypy

or:

  • The gevent server, running on CPython
like image 512
hasen Avatar asked Jan 12 '13 15:01

hasen


People also ask

Is PyPy compatible with Flask?

Python Version We recommend using the latest version of Python 3. Flask supports Python 3.5 and newer, Python 2.7, and PyPy.

Does Flask use gevent?

The charming gevent library will enable you to keep using Flask while start benefiting from all the I/O being asynchronous.

What is gevent Flask?

gevent allows writing asynchronous, coroutine-based code that looks like standard synchronous Python. It uses greenlet to enable task switching without writing async/await or using asyncio . eventlet is another library that does the same thing.

How many requests can a Flask app handle?

For reference, the Flask benchmarks on techempower give 25,000 requests per second.


1 Answers

The short answer is: It's faster with PyPy, and it has higher concurrency with gevent.

It is possible to use gevent and PyPy simultaneously (we do this at PubNub for multiple projects) although it can be tricky. Starting with PyPy 2.2, a few patches are required to gevent on their socket implementation. We have an experimental branch on github for it: https://github.com/pubnub/gevent/tree/pypy-hacks - To be used in conjunction with pypycore.

Our recommendation? Use Flask with PyPy and gevent. Get the best of both worlds!

like image 59
Jason Oster Avatar answered Sep 20 '22 17:09

Jason Oster