F# in the cloud

4,601 views

Published on

In this talk I introduced some key concepts of cloud computing and an example of how we use F#'s support for actors to implement a stateful server architecture succinctly.

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,601
On SlideShare
0
From Embeds
0
Number of Embeds
2,033
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Lowers the cost of failure
  • The biggest advantage of programming with the Actor model, for me, is the fact that each actor is self-contained and implements an explicit protocol, hence making them very easy to reason with and often it’s possible to look at the code and know that there’s obviously no defect rather than no obvious defect, and that distinction is important.The only operation with the inbox which requires synchronization (as far as I know) is with selective receive using inbox.Scan, otherwise, it’s inherently single-threaded inside the body of an agent (a property of the Actor model).
  • F# in the cloud

    1. 1. F# in the Cloud and at Scale Yan Cui (@theburningmonk) Image by Mike Rohde
    2. 2. Who is Gamesys? • Founded in 2001 • #1 in the UK • Handle $5 Billion in turnover annually • First company to launch real money gaming on Facebook • Employ 1,000 globally
    3. 3. Running in the Cloud, at Scale • 1 Million DAU • 250 Million requests/day • 7 Billion rows of analytics events/month • 2 TB of analytics data/month
    4. 4. Running in the Cloud, at Scale • 100% cloud hosted • AWS for Game services • Google App Engine for back-office services • NoSQL databases – DynamoDB, CouchBase, Redis, Neo4j, ... • Google BigQuery for analytics
    5. 5. What is the Cloud? Cloud computing is an expression used to describe a variety of computing concepts that involve a large number of computers connected through a real-time communication network such as the Internet.... Such virtual servers do not physically exist and can therefore be moved around and scaled up (or down) on the fly without affecting the end user arguably, rather like a cloud. - Wikipedia
    6. 6. What is the Cloud? IaaS PaaS SaaS VMs, load balancers, storage, ... Runtime, databa se, web servers, ... Virtual desktop, games, emails, ...
    7. 7. Why the Cloud? • Trade capital cost with operating cost • Lower operating cost • Elastic scaling • Speed and agility • Focus on what differentiates your product • Global infrastructure for your global audience
    8. 8. Why the Cloud - Scalability • Scale up • Scale out • Scale everything! – Your architecture is as scalable as its least scalable part • Scalability != simple choice of language/framework
    9. 9. Travel, Collect, Craft!
    10. 10. Trap Monsters
    11. 11. Stateful Server EC2 Elastic Load Balancer CloudFront Server A Server B ... Auto scaling Group S3
    12. 12. Stateful Server • Need to ensure Server affinity – All calls need to be routed to the affined server • Need to balance load – Session lengths vary greatly – Some players are more active than others – Need to avoid hot spots • Need to avoid players hogging a server – Need to be able to scale down!
    13. 13. Stateful Server • Persist player state after short inactivity • Move player to another server after persistence
    14. 14. Why Stateful Server? • 500% efficiency increase • 60% reduction in avg latency • Fewer game servers • No CouchBase cluster • Huge saving on cost
    15. 15. The Actor Model An actor is the fundamental unit of computation which embodies the 3 things • Processing • Storage • Communication that are essential to computation. -Carl Hewitt* * http://bit.ly/HoNHbG
    16. 16. The Actor Model • Everything is an actor • An actor has a mailbox • When an actor receives a message it can: – Create new actors – Send messages to actors it has addresses for – Designate how to handle the next message it receives
    17. 17. Stateful Server • Gatekeeper – Manages the local list of active workers – Spawns new workers • Worker – Manages the states for a player – Optimistic locking – Persist state after period of inactivity
    18. 18. Stateful Server Asynchronous Player B Request Handlers Player A Gatekeeper S3 Worker C Worker B Game Server
    19. 19. Stateful Server Asynchronous Worker A Player A Request Handlers Player B ok Gatekeeper S3 Worker C Worker B Game Server
    20. 20. Stateful Server Asynchronous Worker A Player B Request Handlers Player A Gatekeeper S3 Worker C Worker B Game Server
    21. 21. Stateful Server Asynchronous Worker A Player B Request Handlers Player A Gatekeeper Worker C Game Server S3
    22. 22. Stateful Server Asynchronous Worker A Player B Request Handlers Player A Gatekeeper Worker C Game Server S3
    23. 23. MailboxProcessor<Message>
    24. 24. Async<Message option>
    25. 25. switch state
    26. 26. Why F#? • Time to Market • Efficiency • Correctness • Complexity
    27. 27. Why F#? • Agents – No locks – Asynchronous message passing – Each actor is self-contained and easier to reason with • Pattern matching – Clear and concise way to handle all branch conditions
    28. 28. Why F#? • Async Workflows – Non-blocking IO – Convert synchronous code into asynchronous code with minimal code changes – Similar to C# 5’s async-await feature, but available in F# since 2007!
    29. 29. Thank You!
    30. 30. JackpotJoy Slots http://apps.facebook.com/jackpotjoyslots Bingo Lane http://apps.facebook.com/bingolane Here Be Monsters http://apps.facebook.com/herebemonsters Building a MMORPG http://bit.ly/1hjqoL8 http://slidesha.re/18MD4XY Google I/O 2013 – Here Be BigQuery http://bit.ly/1fHjbce

    ×