optimal protocol for chatty communications
- From:
- snacktime
- Date:
- 2010-10-19 @ 19:18
So I'm dealing specifically with flash based online games to give some
context. So far I've been using the json/xml protocol, which is a
persistent connection. This actually suffers from the same security
issues that http pipe-lining does in that the client can send a huge
number of messages, wait a second, then disconnect. At first glance
you might think that to solve the json/xml protocol issue you just
need an authentication mechanism built into the protocol. The problem
there is that you have to assume the client is untrusted and in the
hands of the enemy. Another approach is to rate limit, which can also
be problematic when accounting for things like network latency.
Http long polling looks appealing, but I can think of a couple
drawbacks to using it. One, the logic to handle sending messages from
server to client is more complicated. The server has to wait until
the client connects to send messages, and it has to implement a queue
system to handle the backlog of messages waiting to be sent to the
client. The client can only receive one message per connection, but
the server might generate 2-3 messages at once. Then there is the
overhead on the client of opening and closing that many connections.
One thing I've never tested is performance testing of http long
polling versus persistent connection with message passing.
Specifically the per message overhead. Sometimes the current wisdom
is based on really old data, and I'm wondering how much of a
difference there really is now days. Let's be really crazy here and
say the application will generate 10 messages per second, which would
be really really high. What's the overhead of one versus another? I
want to do some testing of that, as I think the overhead is not as
much as most might think. The advantage to not using persistent
connections is that you don't have to write custom crap, and can use
stuff that's tried and true like http.
Now for the testing. I'm thinking a good test is to have a flash
client that sends N messages per second for M seconds using both
protocols, and then play with N and M. I'm going to try and get
something working here in the next day or two and I'll report back the
results.
Chris