25

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
hasen
  • 161,647
  • 65
  • 194
  • 231
  • 2
    How about benchmarking it for a task that's relevant to you? I see no way this can be constructive. –  Jan 12 '13 at 15:27
  • This is a specific question, and has 3 potential answers: 1. flask-pypy is obviously faster 2. flask-gevent is obviously faster 3. they're close and/or it's hard to tell without benchmarks. – hasen Jan 12 '13 at 15:47

3 Answers3

19

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!

Jason Oster
  • 1,386
  • 1
  • 13
  • 17
  • 2
    Have a look at [here](https://github.com/gevent/gevent/issues/248). Gevent now supports pypy. – kawing-chiu Aug 19 '15 at 06:40
  • @kawing-chiu Yes. PyPy support is available in the current gevent 1.1 beta releases. Exercising caution is still recommended. The betas are still receiving bug fixes. Just keep an eye on the commit log to see if there are any changes that might affect your application since the last beta release. – Jason Oster Aug 19 '15 at 19:26
5

Pypy is compatible with Gevent +1.1 (http://www.gevent.org/changelog.html). It is also compatible with Python 3. So, why not using both? Pypy will improve processing perfomance while Gevent will help in IO bound tasks (e.g. database queries, web requests) by using underground asynchronous connections.

tebanep
  • 625
  • 1
  • 9
  • 11
1

Builtin flask server is a BaseHTTPServer or so, never use. The best scenario is very likely tornado + pypy or something like that. Benchmark before using though. It also depends quite drastically on what you're doing. The web server + web framework benchmarks are typically hello world kind of benchmarks. Is your application really like that?

Cheers, fijal

fijal
  • 3,190
  • 18
  • 21