tests: ssl: socket.sendall() busy loop when client is reading slowly

https://bitbucket.org/which_linden/eventlet/issue/134
This commit is contained in:
Sergey Shepelev
2013-01-11 17:00:37 +04:00
parent e90285a561
commit c8418a10e4

View File

@@ -1,10 +1,10 @@
from tests import LimitedTestCase, certificate_file, private_key_file
from tests import LimitedTestCase, certificate_file, private_key_file, check_idle_cpu_usage
from tests import skip_if_no_ssl
from unittest import main
import eventlet
from eventlet import util, coros, greenio
from eventlet import util, greenio
import socket
import os
def listen_ssl_socket(address=('127.0.0.1', 0)):
sock = util.wrap_ssl(socket.socket(), certificate_file,
@@ -93,6 +93,47 @@ class SSLTest(LimitedTestCase):
client2.send('after')
server_coro.wait()
@skip_if_no_ssl
def test_sendall_cpu_usage(self):
"""SSL socket.sendall() busy loop
https://bitbucket.org/which_linden/eventlet/issue/134/greenssl-performance-issues
Idea of this test is to check that GreenSSLSocket.sendall() does not busy loop
retrying .send() calls, but instead trampolines until socket is writeable.
BUFFER_SIZE and SENDALL_SIZE are magic numbers inferred through trial and error.
"""
# Time limit resistant to busy loops
self.set_alarm(1)
stage_1 = eventlet.event.Event()
BUFFER_SIZE = 1000
SENDALL_SIZE = 100000
def serve(listener):
conn, _ = listener.accept()
conn.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, BUFFER_SIZE)
self.assertEqual(conn.read(8), 'request')
conn.write('response')
stage_1.wait()
conn.sendall('x' * SENDALL_SIZE)
server_sock = listen_ssl_socket()
server_coro = eventlet.spawn(serve, server_sock)
client_sock = eventlet.connect(server_sock.getsockname())
client_sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, BUFFER_SIZE)
client = util.wrap_ssl(client_sock)
client.write('request')
self.assertEqual(client.read(8), 'response')
stage_1.send()
check_idle_cpu_usage(0.2, 0.1)
server_coro.kill()
class SocketSSLTest(LimitedTestCase):
@skip_if_no_ssl
def test_greensslobject(self):