I'm writing a realtime multiplayer game with adobe AIR and RTMFP. The game uses a server client architecture in which all players are directly connected to a single computer ( host has one output netstream and one input netstream for each player). The problem is that the cpu usage will increase dramatically with the number of connections. 20 players is enough to bring my cpu down to it's knees.
I've made an experiment replacing RTMFP with TCP sockets ( Using AIR ServerSocket for the host ), with this the game handled 20 connections while using only 2% cpu. Unfortunately TCP sockets create a lot of extra lag because of nagle's algorithm so I can't use them as a replacement of RTMFP, but this experiment almost definitely proves that the bottleneck is in the usage of RTMFP NetStreams.
Is such high cpu requirements expeceted? If so, what makes it so cpu intensive? Is there anything I can do to lower the cpu usage?
Some extra data about my game:
I'm not using NetGroups.
The host will send about 15 small messages per second to all clients, all messages target the same method called "msg" and use ByteArray as argument. ( myNetStream.send( "msg", msgByteArrayData ); )
A single game with 20 players is too much for my pc, but 3 game instances with 10 players would still run fine ( although still somewhat high cpu usage )
Thanks in advance for any help you could provide.
interesting. sounds like some kind of N^2 operation might be going on inside NetStream's queues somewhere. it *should* scale linearly.