5 ms·
Nuts & Bolts: Campfire loves Erlang
- axod 17y agoSide point: Why are they still using polling in this day+age :/
- imbriaco 17y agoThe poller works great. Polling definitely not optimal, but Comet isn't without issues of its own. The Erlang poller was a fun project that Jamis and I worked on in our spare time. Transitioning Campfire to use Comet or some other push-based room updating is a much larger undertaking.
- axod 17y ago>> "but Comet isn't without issues of its own." Very high traffic sites manage it without issues. Comet actually massively decreases the load on servers, bandwidth used, and means people get messages as soon as they should - without a delay.
- dabeeeenster 17y agoWhat would your solution be?
- axod 17y agoOh I don't know, maybe use keep alive long polling or something? Maybe with self adjusting timeout. Seriously. Polling the server every 3 seconds???
- aaronblohowiak 17y agoEven with keep alive long polling, you have to reconnect frequently. With alive long polling, you also have the trouble of managing open, persistent connections.
- axod 17y ago"keep alive" eg. Not reconnecting.
- bittersweet 17y agoXMPP, Jabber, AMQP, Rabbitmq are a few keywords that are getting a lot of hype lately.
- skorgu 17y agoDon't forget BOSH.
- aaronblohowiak 17y agoBOSH is a technique to enable the techniques that this posts' gp mentioned over http
- ovi256 17y agoIf I understand well, the client browser polls the server, via JS timers. There is no practical, scalable way for the server to update the client browser, so the client has to poll this way. Their code just answers these polls. Of course, performance wise, this sucks badly, because most of the time polling returns no results.
- axod 17y ago>> "There is no practical, scalable way for the server to update the client browser, so the client has to poll this way." If you say so :/
- lbrandy 17y agohttp://en.wikipedia.org/wiki/Comet_(programming) http://en.wikipedia.org/wiki/Comet_(programming)
- simonw 17y agoThere are a number of practical, scalable (albeit tricky to set up) ways of pushing events from the server to the browser, gathered under the umbrella term Comet. Google have been using Comet for chat within Gmail since around 2005.
- a-priori 17y agoFacebook also uses it, with an Erlang backend, for Facebook Chat.
- davidw 17y agoNo performance comparison with their working C code. Hrmph. Erlang's a better choice for this kind of thing because you don't have to worry about a lot of the things that could go wrong in the C version, and it's a bit higher level than C, but still... C is fast and working code is working code.
- jlouis 17y agoI would presume the Erlang version is much smaller than the C version. Nobody argues that Erlang is faster than C, but it might be fast enough for the task at hand. Functional programs tend to be slower than imperative programs. They also tend to be much smaller. And they tend to be easier to understand and work with once the programmer gets the right mindset. This just shows another area where C is not the only competitor anymore.
- davidw 17y agoSure, all that's true, and are good reasons to reach for Erlang before C when writing something like this. It seems a bit weird to rewrite working code though, and it's unfortunate not to measure it. I would bet on Erlang not being that much slower than C, and like you say, much smaller, nicer, etc... so it would have been interesting to have some data to think about.
- erlanger 17y agoWhen dealing with high concurrency, Erlang will beat C.
- davidw 17y agoWhat is Erlang written in, again? Erlang makes it (a lot) easier to write high concurrency code, if that's how you define 'beat', but it's not "faster".
- erlanger 17y agoYes, you could theoretically struggle to write C code to work like Erlang, but processes are very cheap in Erlang, and distributed, parallel code is extremely easy to write. C performs well, but can be unstable; Yaws performs as well as Nginx. Erlang's greatest advantage is not in its vertical but its horizontal scalability, which does have consequences for performance.
- dugmartin 17y agoI'm surprised to read that the Campfire servers does a mysql connect on each poll. I built an internal tool for my company similar to Campfire but allowed tabbed conversations in the same window (so that you can have a visible thread running with a few people without bothering others). To store messages I used a simple PHP script that wrote out a json object per line to a file named with room+date. To poll for messages when you opened the client it would query the poller script with the room name and it would return all the json objects for the current day as an array plus the length of the file. On each subsequent poll the client would send the room name + the file offset - the server script would then open the file, jump to the offset and read in the rest of the file and return it as an array (empty if no new content) plus the new length of the file. It scaled really well (not that we had Campfire sized loads).