jam231 / sia

Stock market server (part of stock market simulation system).
1 stars 0 forks source link

Heartbeat mechanism #75

Open jam231 opened 10 years ago

jam231 commented 10 years ago

Current mechanism (setting SO_KEEPALIVE via sockopt) can take up to 2h to detect invalid connection state. I propose incorporating heartbeat messages into protocol and the following algorithm for handling dead connection discovery:

  1. Set timer to fire each x seconds with heartbeat signal.
  2. Handle this signal by: For every connection:
    1. If connection has set probably_alive then negate probably_alive and send heartbeat to that connection.
    2. Else remove the connection from pool
  3. On receiving from connection answer for heartbeat set probably_alive on the connection.