Eugene
Eugene

Reputation: 963

GEvent PyWSGI SSL is painfully slow

I'm using gevent.pywsgi server with SSL, and when using IE or Chrome, traffic amount is between 10x and 100x of content size, and transfer speed is very, very slow. Firefox is ok with this though. If I use stunnel instead to provide SSL (with same certificate), everything works fine.

I've made an isolated test case here: http://dl.dropbox.com/u/7138409/Chrome-Test.zip

Happens on both Python 2.6 and 2.7 and on different gevent versions.

Upvotes: 4

Views: 1792

Answers (1)

Eugene
Eugene

Reputation: 963

Stupidity of this error is overwhelming. First, I have dissected the stream using Wireshark and, to my surprise, I have seen that every byte of response was transported in its own SSL segment. The problem turned to be out that I was returning raw bytestrings from my WSGI handlers, while the correct thing was to return them enclosed in a list!

Here is a working example:

import gevent
import gevent.pywsgi


ssl = {
    'certfile':  'ajenti.crt',
    'keyfile': 'ajenti.key',
    'ciphers': 'RC4',
}

def dispatch(env, s_r):
    s_r('200 OK', [('Content-Type', 'text/plain')])
    s = 'a' * 1000
    return [s]

server = gevent.pywsgi.WSGIServer(
    ('0.0.0.0', 8001),
    application=dispatch,
    **ssl
)

server.serve_forever()

Upvotes: 3

Related Questions