SlideShare una empresa de Scribd logo
1 de 18
构建 ActionScript 游戏服务器,
 支持超过 15000 并发连接
Building an ActionScript Game Server with over
        15,000 Concurrent Connections


             Renaun Erickson

                                       1
Basic MMO Game Architecture

                 •   Clients
                 •   Servers
                 •   Databases
                 •   Networking




                          2
MMO Network Considerations


•   Protocols (TCP, UDP, HTTP)
•   Firewalls
•   Latency
•   Packet Size
•   Data Schema



                                 3
Have to be able to create large
 number of connections that can
send packets at a reasonable rate
        and bandwidth




                             4
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
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
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
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
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
Case Study: SpellTraction




Design By: Garth Braithwaite http://www.garthdb.com/ @garthdb
                                                    10
Live Demo and Source Code


• http://renaun.com/serveras/test
• http://renaun.com/serveras/spelltraction/
• https://github.com/renaun/ActionScriptGa
  meServerExamples




                                    11
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
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
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
Libev Socket Implementation
bool 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
Linux Kernel Configurations
/etc/sysctl.conf
net.core.rmem_max = 33554432
net.core.wmem_max = 33554432
net.core.rmem_default = 1048576
net.core.wmem_default = 1048576
net.core.optmem_max = 33554432
net.ipv4.tcp_rmem = 4096 4096 33554432
net.ipv4.tcp_wmem = 4096 4096 33554432
net.ipv4.tcp_mem = 786432 1048576 26777216
net.ipv4.tcp_max_tw_buckets = 360000
net.core.netdev_max_backlog = 30000
net.ipv4.ip_local_port_range = 2048 65535
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_no_metrics_save = 1
net.core.somaxconn = 131072
fs.file-max = 131072

/usr/include/linux/limits.h
NR_OPEN = 65536
/etc/security/limits.conf
*                soft     nofile        65535
*                hard     nofile        65535




                                                16
Client Code
Client




                       Shared Code




Server



                             17
Q/A


  renaun@adobe.com

  http://github.com/renaun

  @renaun

  http://renaun.com/blog




                       18

Más contenido relacionado

La actualidad más candente

BGF 2012 (Browsergames Forum)
BGF 2012 (Browsergames Forum)BGF 2012 (Browsergames Forum)
BGF 2012 (Browsergames Forum)
Christof Wegmann
 
MongoDB on Azure - Tips, Tricks and Examples
MongoDB on Azure - Tips, Tricks and ExamplesMongoDB on Azure - Tips, Tricks and Examples
MongoDB on Azure - Tips, Tricks and Examples
MongoDB
 
Building a Docker Swarm cluster on ARM by Dieter Reuter and Stefan Scherer
Building a Docker Swarm cluster on ARM by Dieter Reuter and Stefan Scherer Building a Docker Swarm cluster on ARM by Dieter Reuter and Stefan Scherer
Building a Docker Swarm cluster on ARM by Dieter Reuter and Stefan Scherer
Docker, Inc.
 

La actualidad más candente (20)

Photon Session / Unite12 Conference
Photon Session / Unite12 ConferencePhoton Session / Unite12 Conference
Photon Session / Unite12 Conference
 
BGF 2012 (Browsergames Forum)
BGF 2012 (Browsergames Forum)BGF 2012 (Browsergames Forum)
BGF 2012 (Browsergames Forum)
 
Highly available Drupal on a Raspberry Pi cluster
Highly available Drupal on a Raspberry Pi clusterHighly available Drupal on a Raspberry Pi cluster
Highly available Drupal on a Raspberry Pi cluster
 
Drupal RPG - A Backend Server Story
Drupal RPG - A Backend Server StoryDrupal RPG - A Backend Server Story
Drupal RPG - A Backend Server Story
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
 
Happy Browser, Happy User! WordSesh 2019
Happy Browser, Happy User! WordSesh 2019Happy Browser, Happy User! WordSesh 2019
Happy Browser, Happy User! WordSesh 2019
 
Ansible 101
Ansible 101Ansible 101
Ansible 101
 
MongoDB on Azure - Tips, Tricks and Examples
MongoDB on Azure - Tips, Tricks and ExamplesMongoDB on Azure - Tips, Tricks and Examples
MongoDB on Azure - Tips, Tricks and Examples
 
Nodejs web,db,hosting
Nodejs web,db,hostingNodejs web,db,hosting
Nodejs web,db,hosting
 
Server architecture & scaling strategy for a sports website
Server architecture & scaling strategy for a sports websiteServer architecture & scaling strategy for a sports website
Server architecture & scaling strategy for a sports website
 
Heroes of Paragon: publishing Unity WebGL game on Facebook
Heroes of Paragon: publishing Unity WebGL game on FacebookHeroes of Paragon: publishing Unity WebGL game on Facebook
Heroes of Paragon: publishing Unity WebGL game on Facebook
 
Microsoft Azure Media Services
Microsoft Azure Media ServicesMicrosoft Azure Media Services
Microsoft Azure Media Services
 
Photon Load Test #1
Photon Load Test #1Photon Load Test #1
Photon Load Test #1
 
Stream processing in Mercari - Devsumi 2015 autumn LT
Stream processing in Mercari - Devsumi 2015 autumn LTStream processing in Mercari - Devsumi 2015 autumn LT
Stream processing in Mercari - Devsumi 2015 autumn LT
 
Windows Azure Virtual Machines And Virtual Networks
Windows Azure Virtual Machines And Virtual NetworksWindows Azure Virtual Machines And Virtual Networks
Windows Azure Virtual Machines And Virtual Networks
 
ansible why ?
ansible why ?ansible why ?
ansible why ?
 
Level Up: 5 Expert Tips for Optimizing WordPress Performance
Level Up: 5 Expert Tips for Optimizing WordPress PerformanceLevel Up: 5 Expert Tips for Optimizing WordPress Performance
Level Up: 5 Expert Tips for Optimizing WordPress Performance
 
Building a Docker Swarm cluster on ARM by Dieter Reuter and Stefan Scherer
Building a Docker Swarm cluster on ARM by Dieter Reuter and Stefan Scherer Building a Docker Swarm cluster on ARM by Dieter Reuter and Stefan Scherer
Building a Docker Swarm cluster on ARM by Dieter Reuter and Stefan Scherer
 
Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)
 
OGDC Datastorage Solution_Mr.Dung, Dinh Nguyen Anh
OGDC Datastorage Solution_Mr.Dung, Dinh Nguyen AnhOGDC Datastorage Solution_Mr.Dung, Dinh Nguyen Anh
OGDC Datastorage Solution_Mr.Dung, Dinh Nguyen Anh
 

Destacado

Social Game
Social GameSocial Game
Social Game
ematrix
 
How_to_build_GameServer_2
How_to_build_GameServer_2How_to_build_GameServer_2
How_to_build_GameServer_2
Peter Rybar
 
Multi thread game server
Multi thread game serverMulti thread game server
Multi thread game server
OnGameServer
 
SDC 3rd 안중원님 - InGame CashShop 개발 하기
SDC 3rd 안중원님 - InGame CashShop 개발 하기SDC 3rd 안중원님 - InGame CashShop 개발 하기
SDC 3rd 안중원님 - InGame CashShop 개발 하기
OnGameServer
 
C/C++调试、跟踪及性能分析工具综述
C/C++调试、跟踪及性能分析工具综述C/C++调试、跟踪及性能分析工具综述
C/C++调试、跟踪及性能分析工具综述
Xiaozhe Wang
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
Xiaozhe Wang
 
anybuild/Hosting casual #1
anybuild/Hosting casual #1anybuild/Hosting casual #1
anybuild/Hosting casual #1
Ryo Kuroda
 

Destacado (20)

Social Game
Social GameSocial Game
Social Game
 
构建ActionScript游戏服务器,支持超过15000并发连接
构建ActionScript游戏服务器,支持超过15000并发连接 构建ActionScript游戏服务器,支持超过15000并发连接
构建ActionScript游戏服务器,支持超过15000并发连接
 
Astral game server
Astral game serverAstral game server
Astral game server
 
China game-server-vpn-to-reduce-delay-abroad
China game-server-vpn-to-reduce-delay-abroadChina game-server-vpn-to-reduce-delay-abroad
China game-server-vpn-to-reduce-delay-abroad
 
閒聊Python應用在game server的開發
閒聊Python應用在game server的開發閒聊Python應用在game server的開發
閒聊Python應用在game server的開發
 
How_to_build_GameServer_2
How_to_build_GameServer_2How_to_build_GameServer_2
How_to_build_GameServer_2
 
Multi thread game server
Multi thread game serverMulti thread game server
Multi thread game server
 
SDC 3rd 안중원님 - InGame CashShop 개발 하기
SDC 3rd 안중원님 - InGame CashShop 개발 하기SDC 3rd 안중원님 - InGame CashShop 개발 하기
SDC 3rd 안중원님 - InGame CashShop 개발 하기
 
Next-generation MMORPG service architecture
Next-generation MMORPG service architectureNext-generation MMORPG service architecture
Next-generation MMORPG service architecture
 
C/C++调试、跟踪及性能分析工具综述
C/C++调试、跟踪及性能分析工具综述C/C++调试、跟踪及性能分析工具综述
C/C++调试、跟踪及性能分析工具综述
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
 
Маркетинг 2015 - основни правила за малкия и среден бизнес
Маркетинг 2015 - основни правила за малкия и среден бизнесМаркетинг 2015 - основни правила за малкия и среден бизнес
Маркетинг 2015 - основни правила за малкия и среден бизнес
 
Почему не работают корпоративные социальные сети?
Почему не работают корпоративные социальные сети?Почему не работают корпоративные социальные сети?
Почему не работают корпоративные социальные сети?
 
はじめてのLWF for Open Hack Day
はじめてのLWF for Open Hack DayはじめてのLWF for Open Hack Day
はじめてのLWF for Open Hack Day
 
resumeh aali1
resumeh aali1resumeh aali1
resumeh aali1
 
Checkout proceso optimizavimas el. parduotuvėse
Checkout proceso optimizavimas el. parduotuvėseCheckout proceso optimizavimas el. parduotuvėse
Checkout proceso optimizavimas el. parduotuvėse
 
Innovative Uses of Technology in International Education
Innovative Uses of Technology in International Education Innovative Uses of Technology in International Education
Innovative Uses of Technology in International Education
 
Ultizing Online Space: Virtual Fairs and Online Conversion Tools (with poll r...
Ultizing Online Space: Virtual Fairs and Online Conversion Tools (with poll r...Ultizing Online Space: Virtual Fairs and Online Conversion Tools (with poll r...
Ultizing Online Space: Virtual Fairs and Online Conversion Tools (with poll r...
 
anybuild/Hosting casual #1
anybuild/Hosting casual #1anybuild/Hosting casual #1
anybuild/Hosting casual #1
 
portfolio_tmajasaari
portfolio_tmajasaariportfolio_tmajasaari
portfolio_tmajasaari
 

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

Similar a Building an ActionScript Game Server with over 15,000 Concurrent Connections (20)

Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Bare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and ChefBare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and Chef
 
PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
PostgresOpen 2013 A Comparison of PostgreSQL Encryption OptionsPostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
 
Kubernetes deployment on bare metal with container linux
Kubernetes deployment on bare metal with container linuxKubernetes deployment on bare metal with container linux
Kubernetes deployment on bare metal with container linux
 
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
 
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
 
php & performance
 php & performance php & performance
php & performance
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
 
Swift Install Workshop - OpenStack Conference Spring 2012
Swift Install Workshop - OpenStack Conference Spring 2012Swift Install Workshop - OpenStack Conference Spring 2012
Swift Install Workshop - OpenStack Conference Spring 2012
 
Advanced RAC troubleshooting: Network
Advanced RAC troubleshooting: NetworkAdvanced RAC troubleshooting: Network
Advanced RAC troubleshooting: Network
 
End to End Processing of 3.7 Million Telemetry Events per Second using Lambda...
End to End Processing of 3.7 Million Telemetry Events per Second using Lambda...End to End Processing of 3.7 Million Telemetry Events per Second using Lambda...
End to End Processing of 3.7 Million Telemetry Events per Second using Lambda...
 
Unidade3 roteiro proxy
Unidade3 roteiro proxyUnidade3 roteiro proxy
Unidade3 roteiro proxy
 
Ironic 140622212631-phpapp02
Ironic 140622212631-phpapp02Ironic 140622212631-phpapp02
Ironic 140622212631-phpapp02
 
Ironic
IronicIronic
Ironic
 
Ironic 140622212631-phpapp02
Ironic 140622212631-phpapp02Ironic 140622212631-phpapp02
Ironic 140622212631-phpapp02
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetes
 
A.java
A.javaA.java
A.java
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf eu
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

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

  • 1. 构建 ActionScript 游戏服务器, 支持超过 15000 并发连接 Building an ActionScript Game Server with over 15,000 Concurrent Connections Renaun Erickson 1
  • 2. Basic MMO Game Architecture • Clients • Servers • Databases • Networking 2
  • 3. MMO Network Considerations • Protocols (TCP, UDP, HTTP) • Firewalls • Latency • Packet Size • Data Schema 3
  • 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
  • 10. Case Study: SpellTraction Design By: Garth Braithwaite http://www.garthdb.com/ @garthdb 10
  • 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
  • 15. Libev Socket Implementation bool 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. Linux Kernel Configurations /etc/sysctl.conf net.core.rmem_max = 33554432 net.core.wmem_max = 33554432 net.core.rmem_default = 1048576 net.core.wmem_default = 1048576 net.core.optmem_max = 33554432 net.ipv4.tcp_rmem = 4096 4096 33554432 net.ipv4.tcp_wmem = 4096 4096 33554432 net.ipv4.tcp_mem = 786432 1048576 26777216 net.ipv4.tcp_max_tw_buckets = 360000 net.core.netdev_max_backlog = 30000 net.ipv4.ip_local_port_range = 2048 65535 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_no_metrics_save = 1 net.core.somaxconn = 131072 fs.file-max = 131072 /usr/include/linux/limits.h NR_OPEN = 65536 /etc/security/limits.conf * soft nofile 65535 * hard nofile 65535 16
  • 17. Client Code Client Shared Code Server 17
  • 18. Q/A renaun@adobe.com http://github.com/renaun @renaun http://renaun.com/blog 18

Notas del editor

  1. MMO Server Architecture
  2. Explain what SpellTraction is.