Your SlideShare is downloading. ×
  • Like
Stateful Application Server_JRubyConf13_Lukas Rieder
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Stateful Application Server_JRubyConf13_Lukas Rieder

  • 784 views
Published

After more than one year of development, Wooga is heading for the global launch of its game "Kingsbridge"! …

After more than one year of development, Wooga is heading for the global launch of its game "Kingsbridge"!

This is the first game at Wooga with a backend written in JRuby!

The talk includes an introduction to the problems that were solved by choosing a stateful applicaton server.

I will explain constraints, benefits and obvious differences to traditional database backed application servers.

Safely sharing state in a concurrent environment using JRuby
Using Java concurrency utils in JRuby
Sample problems solved, backed up with code
Practical tips for capacity planning

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
784
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
14
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. stateful application server
  • 2. Hi I’m Lukas @Overbryd
  • 3. Working @Wooga
  • 4. stateful application server
  • 5. database based system
  • 6. app app app load db clients
  • 7. stateful system
  • 8. app app app client
  • 9. app app app dns load clients
  • 10. every server is equal
  • 11. app nginx jvm redis ssd
  • 12. state
  • 13. jvm {}
  • 14. ‣ SessionManager ‣ Session ‣ Resources ‣ Items ‣ Quests ‣ Payments ...
  • 15. the hard part
  • 16. one place at a time
  • 17. easy with one server, but how to scale out?
  • 18. sharding!
  • 19. “static sharding” shard = facebook_id % shards
  • 20. raise Invalid, “wrong shard” unless Shard.valid?(facebook_id)
  • 21. concurrency
  • 22. jvm http threads sessions ticker thread worker threads
  • 23. the hard part
  • 24. serialized access to a session
  • 25. easy for low contention like a single session
  • 26. class Session attr_reader :lock def initialize @lock = Mutex.new end # ... end session.lock.synchronize do session.foo end
  • 27. harder for high contention like the SessionManager
  • 28. class SessionManager @current = ConcurrentHashMap.new def self.get(id) raise WrongShard unless Shard.valid?(id) unless session = @current.get(id) new_session = create(id) unless session = @current.put_if_absent(id, new_session) session = new_session end end session end end
  • 29. t1 t2 {} S S
  • 30. t1 t2 {} S S
  • 31. t1 t2 {} S S session = @current.get(id) # => nil session = @current.get(id) # => nil
  • 32. S2 t1 t2 {} S S
  • 33. S2 t1 t2 {} S S S1 S2
  • 34. S2 t1 t2 {} S S S1 S2 S2
  • 35. S2 t1 t2 {} S S S1 S2 S2 S2
  • 36. S2 t1 t2 {} S S S1 S2 S2 S2
  • 37. S2 new_session = create(id) unless session = @current.put_if_absent(id, new_session) # => nil session = new_session # => #<Session:0x2> end t1 new_session = create(id) unless session = @current.put_if_absent(id, new_session) # => #<Session:0x2> t2 {} S S S1 S2 S2 S2
  • 38. deployment
  • 39. the hard part
  • 40. one place at a time
  • 41. handover
  • 42. app nginx jvm1 jvm2 S1
  • 43. app nginx jvm1 jvm2 S1
  • 44. app nginx jvm1 jvm2 S1
  • 45. app nginx jvm2 S1
  • 46. global state
  • 47. weird problem when handling sharded state
  • 48. even weirder when every machine should be equal
  • 49. app nginx jvm redis ssd
  • 50. global data is kept local
  • 51. populates via UPD broadcast
  • 52. not “a huge” problem if stale
  • 53. last write wins self healing
  • 54. class Broadcast def self.spawn_listener Thread.new do socket = wait_until_socket_bind loop do if @stop_listener socket.close return end message, from = socket.recvfrom(1024) handle_message(message) end end end end
  • 55. appjvm redis appjvm redis internal network jvm
  • 56. appjvm redis appjvm redis internal network jvm
  • 57. appjvm redis appjvm redis internal network jvm