Building an ActionScript Game Server with over 15,000 Concurrent Connections

2,980
-1

Published on

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.

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,980
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • MMO Server Architecture
  • Explain what SpellTraction is.
  • Building an ActionScript Game Server with over 15,000 Concurrent Connections

    1. 1. 构建 ActionScript 游戏服务器, 支持超过 15000 并发连接Building an ActionScript Game Server with over 15,000 Concurrent Connections Renaun Erickson 1
    2. 2. Basic MMO Game Architecture • Clients • Servers • Databases • Networking 2
    3. 3. MMO Network Considerations• Protocols (TCP, UDP, HTTP)• Firewalls• Latency• Packet Size• Data Schema 3
    4. 4. Have to be able to create large number of connections that cansend packets at a reasonable rate and bandwidth 4
    5. 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. 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. 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 serverIs ActionScript on the server possible? 7
    8. 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. 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
    10. 10. Case Study: SpellTractionDesign By: Garth Braithwaite http://www.garthdb.com/ @garthdb 10
    11. 11. Live Demo and Source Code• http://renaun.com/serveras/test• http://renaun.com/serveras/spelltraction/• https://github.com/renaun/ActionScriptGa meServerExamples 11
    12. 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. 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. 14. Server ActionScript Codefunction 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
    15. 15. Libev Socket Implementationbool ServerSocketObject::_listen(Stringp host, const int port){ struct socket_io w_accept; StUTF8String hostUTF8(host); const char* hostAddr = hostUTF8.c_str(); if( (w_accept.fd = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) return false; int flags = fcntl(w_accept.fd, F_GETFL, 0); fcntl(w_accept.fd, F_SETFL, (flags > 0 ? flags : 0) | O_NONBLOCK); sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(hostAddr); addr.sin_port = htons(port); int status = bind(w_accept.fd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)); if (status != 0) return false; _socket = w_accept.fd; if (listen(w_accept.fd, 2) < 0) return false; w_accept.socketObject = this; // Initialize and start a watcher to accepts client requests ev_io_init(&w_accept.io, accept_cb, w_accept.fd, EV_READ); ev_io_start(loop_ev, &w_accept.io); ev_loop(loop_ev, 0); return true;} 15
    16. 16. Linux Kernel Configurations/etc/sysctl.confnet.core.rmem_max = 33554432net.core.wmem_max = 33554432net.core.rmem_default = 1048576net.core.wmem_default = 1048576net.core.optmem_max = 33554432net.ipv4.tcp_rmem = 4096 4096 33554432net.ipv4.tcp_wmem = 4096 4096 33554432net.ipv4.tcp_mem = 786432 1048576 26777216net.ipv4.tcp_max_tw_buckets = 360000net.core.netdev_max_backlog = 30000net.ipv4.ip_local_port_range = 2048 65535net.ipv4.tcp_window_scaling = 1net.ipv4.tcp_no_metrics_save = 1net.core.somaxconn = 131072fs.file-max = 131072/usr/include/linux/limits.hNR_OPEN = 65536/etc/security/limits.conf* soft nofile 65535* hard nofile 65535 16
    17. 17. Client CodeClient Shared CodeServer 17
    18. 18. Q/A renaun@adobe.com http://github.com/renaun @renaun http://renaun.com/blog 18

    ×