<html><body><span style="font-family:Verdana; color:#000000; font-size:10pt;"><div>Eric,</div><div>   Thanks for your experimentation and analysis. Somewhat illustrates the point about premature optimization. First cut, have to agree with you and conclude that python implementation is effective, overall. As you said,if we find performance bottlenecks, especially as the payload size increases (as well as if we require any complex processing at the http server layer) we can optimize specific areas.</div><div><br></div><div>    Just for sure, might be better for someone else to recheck. That way we have done our due diligence.<br></div><div><br></div><div>Cheers</div><div><k/><br></div>
<blockquote id="replyBlockquote" webmail="1" style="border-left: 2px solid blue; margin-left: 8px; padding-left: 8px; font-size: 10pt; color: black; font-family: verdana;">
<div id="wmQuoteWrapper">
-------- Original Message --------<br>
Subject: [Openstack] Queue Service Implementation Thoughts<br>
From: Eric Day <<a href="mailto:eday@oddments.org">eday@oddments.org</a>><br>
Date: Sat, March 05, 2011 4:07 pm<br>
To: <a href="mailto:openstack@lists.launchpad.net">openstack@lists.launchpad.net</a><br>
<br>
Hi everyone,<br>
<br>
When deciding to move forward with Erlang, I first tried out the Erlang<br>
REST framework webmachine (it is built on top of mochiweb and used<br>
by projects like Riak). After some performance testing, I decided to<br>
write a simple wrapper over the HTTP packet parsing built into Erlang<br>
(also used by mochiweb/webmachine) to see if I could make things a<br>
bit more efficient. Here are the results:<br>
<br>
Erlang (2 threads)<br>
  echo - 58823 reqs/sec<br>
  webmachine - 7782 reqs/sec<br>
  openstack - 24154 reqs/sec<br>
<br>
The test consists of four concurrent connections focused on packet<br>
parsing speed and framework overhead. A simple echo test was also<br>
done for a baseline (no parsing, just a simple recv/send loop). As<br>
you can see, the simple request/response wrapper I wrote did get some<br>
gains, although it's a little more hands-on to use (looks more like<br>
wsgi+webob in python).<br>
<br>
I decided to run the same tests against Python just for comparison. I<br>
ran echo, wsgi, and wsgi+webob decorators all using eventlet. I ran<br>
both single process and two process in order to compare with Erlang<br>
which was running with two threads.<br>
<br>
Python (eventlet)<br>
  echo (1 proc) - 17857 reqs/sec<br>
  echo (2 proc) - 52631 reqs/sec<br>
  wsgi (1 proc) - 4859 reqs/sec<br>
  wsgi (2 proc) - 8695 reqs/sec<br>
  wsgi webob (1 proc) - 3430 reqs/sec<br>
  wsgi webob (2 proc) - 6142 reqs/sec<br>
<br>
As you can see, the two process Python echo server was not too far<br>
behind the two thread Erlang echo server. The wsgi overhead was<br>
significant, especially with the webob decorators/objects. It was<br>
still on par with webmachine, but a factor of three less than my<br>
simple request/response wrapper.<br>
<br>
A multi-process python server does have the drawback of not being<br>
able to share resources between processes unless incurring the<br>
overhead of IPC. When thinking about a horizontally scalable service,<br>
where scaling-out is much more important than scaling-up, I think<br>
this becomes much less of a factor. Regardless of language choice,<br>
we will need a proxy to efficiently hash to a set of queue servers in<br>
any large deployment (or the clients will hash), but if that set is a<br>
larger number of single-process python servers (some running on the<br>
same machine) instead of a smaller number of multi-threaded Erlang<br>
servers, I don't think it will make too much of a difference (each<br>
proxy server will need to maintain more connections). In previous<br>
queue service threads I was much more concerned about this and was<br>
leaning away from Python, but I think I may be coming around.<br>
<br>
Another aspect I took a look at is options for message storage. For<br>
the fast, in-memory, unreliable queue type, here are some numbers<br>
for options in Python and Erlang:<br>
<br>
Raw message = key(16) + ttl(8) + hide(8) + body(100) = 132 bytes<br>
Python list/dict - 248 bytes/msg (88% overhead)<br>
Python sqlite3 - 168 bytes/msg (27% overhead)<br>
Erlang ets - 300 bytes/msg (127% overhead)<br>
<br>
The example raw message has no surrounding data structure, so it is<br>
obviously never possible to get down to 132 bytes. As the body grows,<br>
the overhead becomes less significant since they all grow the same<br>
amount. The best Python option is probably an in-memory sqlite table,<br>
which is also an option for disk-based storage as well.<br>
<br>
For Erlang, ets is really the only efficient in-memory option (mnesia<br>
is built on ets if you're thinking of that), and also has a disk<br>
counterpart called dets. The overhead was definitely more than I was<br>
expecting and is less memory efficient than both Python options.<br>
<br>
As we start looking at other stores to use, there are certainly more<br>
DB drivers available for Python than Erlang (due to the fact that<br>
Python is more popular). We'll want to push most of the heavy lifting<br>
to the pluggable databases, which makes the binding language less of<br>
a concern as well.<br>
<br>
So, in conclusion, and going against my previous opinion, I'm starting<br>
to feel that the performance gains of Erlang are really not that<br>
significant compared to Python for this style of application. If<br>
we're talking about a factor of three (and possibly less if we can<br>
optimize the wsgi driver or not use wsgi), and consider the database<br>
driver options for queue storage, Python doesn't look so bad. We'll<br>
certainly have more of a developer community too.<br>
<br>
We may still need to write parts in C/C++ if limits can't be overcome,<br>
but that would probably be the case for Erlang or Python.<br>
<br>
What do folks think?<br>
<br>
-Eric<br>
<br>
_______________________________________________<br>
Mailing list: <a href="https://launchpad.net/~openstack">https://launchpad.net/~openstack</a><br>
Post to     : <a href="mailto:openstack@lists.launchpad.net">openstack@lists.launchpad.net</a><br>
Unsubscribe : <a href="https://launchpad.net/~openstack">https://launchpad.net/~openstack</a><br>
More help   : <a href="https://help.launchpad.net/ListHelp">https://help.launchpad.net/ListHelp</a><br>

</div>
</blockquote></span></body></html>