Building a server to manage high concurrent connections is non-trival task. For those developers that use ActionScript 3 to build games on the client side it means having a totally different skillset. Being able to use ActionScript 3 on the server to build MMO’s or port client code to the server allows developers to leverage their skills on the server.
By walking through a live game example with more then 15,000 concurrent connections running on a medium Amazon EC2 server the presentation will:
1. Introduce Linux server configuration for high concurrent connected usage.
2. Introduce Socket class based on libev library for high concurrent connection.
3. Introduce leveraging Tamarin project for ActionScript 3 on the server.
4. Have to be able to create large
number of connections that can
send packets at a reasonable rate
and bandwidth
4
5. Socket Implementations
• Check each file descriptor each frame
– Select, poll
• Slow for large number of connections
• OS Optimized
– Epoll, kqueue, /dev/poll, pollset, I/O Completion
Ports
• OS specific fast implementations
• Event based libraries
– Libevent and libev
• Fast for large number of connections
• Portable code, hides OS specific implementations
5
6. Server Configuration
• Tell OS to allow large number of file
descriptors
• Tell OS how much ram for each file
descriptor
• Tell OS buffer sizes for network protocols
• Tell OS what ports range to use, only 65k
ports per IP
6
7. Flash on the Client and Server
• Many MMOs in China use Flash as the
Client
• Server naturally has MMO game logic
• Put game logic on server for security
• Many benefits of using the same
language on client and server
Is ActionScript on the server possible?
7
8. ActionScript on the Server
• Flash Player Dissected
– Core – VM, Primitives, ActionScript syntax
– APIs – C/C++ classes implementing rich Flash
Player API and features
• Tamarin
– Open sourced core parts of the Flash Player
– No rich API or features, you have to write
them yourself
8
9. Tamarin Projects
• Thane (part of Whirled SDK by ThreeRings)
– http://wiki.whirled.com/Whirled_SDK
• Redtamarin (by zwetan and others)
– http://code.google.com/p/redtamarin/
• PushButton Engines Network component by
Ben Garney
– https://github.com/PushButtonLabs/PBNetwork
ing
9
11. Live Demo and Source Code
• http://renaun.com/serveras/test
• http://renaun.com/serveras/spelltraction/
• https://github.com/renaun/ActionScriptGa
meServerExamples
11
12. Server Setup
• Game Server
– Amazon EC2 Medium Server
– 64 bit Ubuntu OS
– Running two game instances
• Main
• Load Test
• Load Test Server
– Amazon EC2 Medium Server
– Custom test scripts
12
13. Server Code
• Redtamarin
– Created ServerSocket.as – libev socket
implementation
– Compile ActionScript files into ActionScript
Byte Code (abc files)
– Command line redtamarin shell runs the abc
files
13
14. Server ActionScript Code
function loopHandler():void
{
if (!ss.listening)
ss.listen("10.111.33.190", 12122);
else
serverBrain.beat(); // Game Tick
}
var serverDispatcher:SocketServerNerveDispatcher
= new SocketServerNerveDispatcher();
var serverBrain:ServerBrain = new ServerBrain();
var serverNerve:ServerNerveSystem
= new ServerNerveSystem(serverBrain, serverDispatcher);
serverBrain.addNerve(serverNerve);
var ss:ServerSocket
= serverDispatcher.createServerSocket(serverNerve);
ss.loop.add(loopHandler);
ss.start(250);
14