469,336 Members | 5,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Wierd problem with python sockets and threading

I have two python "applications" (more like scripts, they're only
about 80 lines each) that are dumbed down http-servers: They accept a
connection, reads everything in the socket untill "\r\n\r\n" and then
responds with "HTTP/1.1 200 OK\r\n\r\nHello World!" and then closes
the connection.

There is one multiplexing single-threaded one and one multithreaded
one, when I use apache bench with something like "ab -n 5000 -c 5
http://localhost/" everything works fine (about ~1500req/s each) - but
when I raise the concurrency (-c command in apache bench) of the bench
to something that is above the socket.listen(10) (ten in this case)
call in the server socket something strange happens: In the
multiplexing version everything still works fine, pulling ~1400req/s
or there about, but here is my problem:

In the multithreaded version of the code, when the concurrency level
in apache bench is raised above the socket.listen(10) call (say 11 or
100) performance dropps through the floor to something like ~10req/s.
But as long as the concurrency level stays less then or equal to the
socket.listen()-call everything works fine.

I've been staring at this problem for a day now, unable to figure it
out - I don't think I have any long locking times for the connection
queue used between the threads (and I can't see how they could occur
when the concurrency level is raised) and just can't see the reason.

Here's the code: http://paste2.org/p/89679 about 80 lines and it runs
as it is, no external deps. Any ideas/tips are greatly appriciated.

Regards, Fredrik.
Oct 20 '08 #1
0 648

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.