Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Mobile Gameserver Backend in D
Stephan Dilly
@Extrawurst
5/23/2014
Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 1 / 28
Structure
1 The Author
2 STACK4
3 STACK4 Multiplayer
4 D at Funatics
5 Conclusion
Stephan Dilly (@Extrawurst) #dconf2014 5...
The Author
Personal
Stephan Dilly
28 years old
Programming for 15 years
Game Industry for 7 years
Software Engineer at Fun...
The Author
Track Record
2007 The Settlers - Rise of Cultures (PC)
2008 Tom Clancy’s Endwar (NDS/PSP)
2009 24-Fun
2010 Cult...
The Author
D experience
Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 5 / 28
The Author
D experience
2006 First encounter with D
2007 First dmd bug report ;)
2008 Thesis about game development in D
2...
STACK4
The Game
Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 7 / 28
STACK4
The Game
Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 8 / 28
STACK4
History
05/22/2013 Repo created
06/17/2013 First Release on Android
07/30/2013 Release on Blackberry10
12/18/2013 A...
STACK4 Multiplayer
Structure
Requirements
Research
Vibe.d
Architecture
Implementation
Stephan Dilly (@Extrawurst) #dconf20...
STACK4 Multiplayer
Requirements
Supports long polling (sockjs)
Fast and memory efficient
Compatible with our consumer server...
STACK4 Multiplayer
Nodejs
Simple event driven io
great community (npm)
javascript, typescript
callback hell
Stephan Dilly ...
STACK4 Multiplayer
Java
statically typed
proven, huge knowledge base/community
vertx.io for evented io
big memory footprin...
STACK4 Multiplayer
Vibe.d - Introduction
Vladimir’s Talk at dconf2013
”Asynchronous I/O for maximum speed and minimum memo...
STACK4 Multiplayer
Vibe.d - Comparison
1 var http = r e q u i r e ( ” http ” ) ;
2 var f s = r e q u i r e ( ” f s ” ) ;
3...
STACK4 Multiplayer
Vibe.d - Comparison
1 import v i b e . d ;
2
3 void handleRequest (
4 HTTPServerRequest req ,
5 HTTPSer...
STACK4 Multiplayer
Backend architecture
LoadbalancerSmartphone Firewall
UserDB (MySQL)
User
Stephan Dilly (@Extrawurst) #d...
STACK4 Multiplayer
Libraries
forever-d
sockjs-d
sockjs-unity3d-xhr
elo-rating-d
xtea-d
gcm-d/apn-d
find the libraries on gi...
STACK4 Multiplayer
syslogclient.log template
1 // b e f o r e
2 l o g g e r . log ! ” event2 ” ( [
3 ”param2” : to ! s t r...
STACK4 Multiplayer
syslogclient.log template
1 void log ( s t r i n g event , T . . . ) ( i n T params ) {
2
3 s t a t i c...
STACK4 Multiplayer
syslogservice.equalComponents
1 // b e f o r e
2 i f ( currentTime . year != m lastFileNameUpdateTime ....
STACK4 Multiplayer
syslogservice.equalComponents
1 bool equalComponents (T,COMPONENTS . . . ) (T a , T b ) {
2
3 foreach (...
STACK4 Multiplayer
MsgType send/parse enhancement
1 // b e f o r e
2 i f ( a r g s . length == 3) {
3 i n t paramJoin , ga...
D at Funatics
D components
webapi
loginapi
clientconfigapi
syslogservice
Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 2...
Conclusion
What rocks
Performance
Build speed
Syntax,Templates
Mono-D
Vibe.d and DUB
we had an itch - so we scratched it
S...
Conclusion
What rocks not so much
GC in Phobos
Exceptions in vibe.d
GUI
Debugging on windows
Stephan Dilly (@Extrawurst) #...
Conclusion
Future directions
D in STACK4
D at Funatics
D Games using Amazon AppStream (maybe using aurora?)
Stephan Dilly ...
Thank you for your attention!
Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 28 / 28
Upcoming SlideShare
Loading in …5
×

DConf21014 - Mobile Gameserver Backend in D - Stephan Dilly

4,808 views

Published on

A gameserver backend that was developed for a mobile game app project. The server is completely written in D using the vibe.d framework.

Published in: Software
  • Be the first to comment

DConf21014 - Mobile Gameserver Backend in D - Stephan Dilly

  1. 1. Mobile Gameserver Backend in D Stephan Dilly @Extrawurst 5/23/2014 Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 1 / 28
  2. 2. Structure 1 The Author 2 STACK4 3 STACK4 Multiplayer 4 D at Funatics 5 Conclusion Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 2 / 28
  3. 3. The Author Personal Stephan Dilly 28 years old Programming for 15 years Game Industry for 7 years Software Engineer at Funatics Software GmbH Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 3 / 28
  4. 4. The Author Track Record 2007 The Settlers - Rise of Cultures (PC) 2008 Tom Clancy’s Endwar (NDS/PSP) 2009 24-Fun 2010 Cultures Online 2011 Ufo Online 2012 Panzer General Online Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 4 / 28
  5. 5. The Author D experience Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 5 / 28
  6. 6. The Author D experience 2006 First encounter with D 2007 First dmd bug report ;) 2008 Thesis about game development in D 2009 Multiple hobby projects 2013 STACK4 Server Backend 2014 FunNetX Server Backend Components Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 6 / 28
  7. 7. STACK4 The Game Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 7 / 28
  8. 8. STACK4 The Game Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 8 / 28
  9. 9. STACK4 History 05/22/2013 Repo created 06/17/2013 First Release on Android 07/30/2013 Release on Blackberry10 12/18/2013 Added Online Multiplayer 05/13/2014 Release on iOS Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 9 / 28
  10. 10. STACK4 Multiplayer Structure Requirements Research Vibe.d Architecture Implementation Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 10 / 28
  11. 11. STACK4 Multiplayer Requirements Supports long polling (sockjs) Fast and memory efficient Compatible with our consumer server Easy upscaling Fast development process Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 11 / 28
  12. 12. STACK4 Multiplayer Nodejs Simple event driven io great community (npm) javascript, typescript callback hell Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 12 / 28
  13. 13. STACK4 Multiplayer Java statically typed proven, huge knowledge base/community vertx.io for evented io big memory footprint in our case Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 13 / 28
  14. 14. STACK4 Multiplayer Vibe.d - Introduction Vladimir’s Talk at dconf2013 ”Asynchronous I/O for maximum speed and minimum memory usage” ”Fiber based” Simple RESTful services Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 14 / 28
  15. 15. STACK4 Multiplayer Vibe.d - Comparison 1 var http = r e q u i r e ( ” http ” ) ; 2 var f s = r e q u i r e ( ” f s ” ) ; 3 4 http . c r e a t e S e r v e r ( f u n c t i o n ( req , r e s ) { 5 r e s . writeHead (200 , { ’ content −type ’ : ’ t e x t / p l a i n ’ }) ; 6 7 setTimeout ( f u n c t i o n () { 8 f s . appendFile ( ’ log . t x t ’ , ’ dat to append ’ , f u n c t i o n ( e r r ) { 9 i f ( e r r ) throw e r r ; 10 11 r e s . end ( ”World ! ” ) ; 12 }) ; 13 } , 1000) ; 14 }) . l i s t e n (80) ; Listing 1: node example Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 15 / 28
  16. 16. STACK4 Multiplayer Vibe.d - Comparison 1 import v i b e . d ; 2 3 void handleRequest ( 4 HTTPServerRequest req , 5 HTTPServerResponse r e s ) { 6 7 s l e e p ( 1 . seconds ) ; 8 9 appendToFile ( ” log . t x t ” , ” dat to append” ) ; 10 11 r e s . writeBody ( ” Hello World ! ” ) ; 12 } 13 14 shared s t a t i c t h i s () { 15 listenHTTP (new HTTPServerSettings , &handleRequest ) ; 16 } Listing 2: vibe.d example Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 16 / 28
  17. 17. STACK4 Multiplayer Backend architecture LoadbalancerSmartphone Firewall UserDB (MySQL) User Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 17 / 28
  18. 18. STACK4 Multiplayer Libraries forever-d sockjs-d sockjs-unity3d-xhr elo-rating-d xtea-d gcm-d/apn-d find the libraries on github under https://github.com/Extrawurst/... Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 18 / 28
  19. 19. STACK4 Multiplayer syslogclient.log template 1 // b e f o r e 2 l o g g e r . log ! ” event2 ” ( [ 3 ”param2” : to ! s t r i n g (12) , 4 ”param3” : to ! s t r i n g ( t r u e ) ] ) ; 5 6 // a f t e r 7 l o g g e r . log ! ” event2 ” ( 8 ”param2” , 42 , 9 ”param3” , t r u e ) ; Listing 3: example Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 19 / 28
  20. 20. STACK4 Multiplayer syslogclient.log template 1 void log ( s t r i n g event , T . . . ) ( i n T params ) { 2 3 s t a t i c a s s e r t (T. leng th % 2 == 0 , ”odd number of parameters r e q u i r e d ” ) ; 4 5 i f ( m url . len gth == 0) 6 r e t u r n ; 7 8 s t r i n g [T. length ] paramArray ; 9 10 foreach ( i , param ; params ) { 11 12 paramArray [ i ] = to ! s t r i n g ( param ) ; 13 } 14 15 // s n i p : a c t u a l l o g g i n g . . . 16 } Listing 4: implementation Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 20 / 28
  21. 21. STACK4 Multiplayer syslogservice.equalComponents 1 // b e f o r e 2 i f ( currentTime . year != m lastFileNameUpdateTime . year | | 3 currentTime . month != m lastFileNameUpdateTime . month | | 4 currentTime . day != m lastFileNameUpdateTime . day | | 5 currentTime . hour != m lastFileNameUpdateTime . hour ) 6 {} 7 8 // a f t e r 9 i f ( ! equalComponents ! ( SysTime , ” year ” , ”month” , ”day” , ” hour ” ) ( currentTime , m lastFileNameUpdateTime ) ) 10 {} Listing 5: example Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 21 / 28
  22. 22. STACK4 Multiplayer syslogservice.equalComponents 1 bool equalComponents (T,COMPONENTS . . . ) (T a , T b ) { 2 3 foreach (comp ; COMPONENTS) { 4 5 s t a t i c a s s e r t ( i s ( typeof (comp) : s t r i n g ) , 6 ”components must be s t r i n g ” ) ; 7 8 s t a t i c a s s e r t ( t r a i t s ( compiles , mixin ( ” a . ”˜comp) ) , 9 ” ’ ”˜comp˜” ’ i s not a member of ’ ”˜T. s t r i n g o f ˜” ’ ” ) ; 10 11 mixin ( ” i f ( a . ”˜comp˜”!= b . ”˜comp˜” ) r e t u r n f a l s e ; ” ) ; 12 } 13 14 r e t u r n t r u e ; 15 } Listing 6: implementation Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 22 / 28
  23. 23. STACK4 Multiplayer MsgType send/parse enhancement 1 // b e f o r e 2 i f ( a r g s . length == 3) { 3 i n t paramJoin , gametypes ; 4 5 i f ( t r y P a r s e ! i n t ( a r g s [ 1 ] , paramJoin ) && 6 t r y P a r s e ! i n t ( a r g s [ 2 ] , gametypes ) ) 7 { . . . } 8 } 9 10 // a f t e r 11 t r y { 12 auto r e s = parseMsg ! MsgMatchMake( a r g s [ 1 . . $ ] ) ; 13 . . . 14 } 15 catch ( MsgParseException e ) { . . . } Listing 7: example Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 23 / 28
  24. 24. D at Funatics D components webapi loginapi clientconfigapi syslogservice Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 24 / 28
  25. 25. Conclusion What rocks Performance Build speed Syntax,Templates Mono-D Vibe.d and DUB we had an itch - so we scratched it Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 25 / 28
  26. 26. Conclusion What rocks not so much GC in Phobos Exceptions in vibe.d GUI Debugging on windows Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 26 / 28
  27. 27. Conclusion Future directions D in STACK4 D at Funatics D Games using Amazon AppStream (maybe using aurora?) Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 27 / 28
  28. 28. Thank you for your attention! Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 28 / 28

×