Just soliciting ideas on a client/server messaging system. Ideas, suggestions, etc.
Currently, I am thinking along these lines:
SERVER:
+ Main thread listens on a certain port. When a request comes in on that port, it spawns a WORKER to handle the request and goes back to listening. My thoughts on this: requests need to be grabbed quickly so the port isn't tied up. I know on a massive system this might cause lots of thread creates/deletes, but I rarely expect more than 1000 destinations, and maybe 5% are sending at once (high estimate IMHO), so that's 50 threads at most. I figure average rate is gonna be closer to 10 threads at most.
+ WORKER receives the data. Normally it is a send message request. (for heartbeat req see below) First step is to see if recipient is listed in the ACTIVE table; if so, it tries to deliver to the destination. If it succeeds, then all is well. If it fails, it drops the message into WAITING and also removes the destination from the ACTIVE table. If the destination is not listed in ACTIVE, it just immediately drops it into WAITING.
+ GARBAGE. Clients must send heartbeat every 15 minutes. Last heartbeat is entered into ACTIVE table. GARBAGE runs every 20 minutes, and any clients that have not sent heartbeat since 20 minutes are removed from the ACTIVE table. GARBAGE also ticks all messages in WAITING table; if a message receives more than X ticks (maybe 100,000?) it is considered orphaned and removed.
+ WORKER (heartbeat). If the data is a heartbeat signal, then worker just updates the last heartbeat field in ACTIVE and sends an OK response to the client.
+ WORKER (connect). When client connects, worker authenticates with whatever auth package admin has set, enters client into ACTIVE, then retrieves all messages for client that are in WAITING. Auth for starters it will be a USERS table, but i plan on having AD integration at some point
+ WORKER (disconnect). When client shuts down orderly, it sends disconnect. Worker removes client from ACTIVE table.
In this configuration, ACTIVE should have a relatively up-to-date picture of what destinations are currently reachable. WAITING stores all messages for clients that are not, to be delivered upon next connect.
Garbage ensures that you don't end up with undelivered messages in WAITING from 10 years ago causing the database to grow forever, and also ensures that if a destination goes offline suddenly without sending disconnect, it won't be stuck listed as 'online' forever.
I haven't quite worked out the best way to do the client yet... but it will probably be something like this:
This single-threaded app handles the UI and stuff. It also listens on the proper port. Whenever a server has a message for this destination, it will connect to this port to deliver it. The IP/port combo is listed in Active when client connects.
Received messages are posted where appropriate, and any messages to be sent are handled as needed.
Opinions? I think a setup like this would scale fairly well to a few thousand users at most, would allow for timely (yet disconnected) delivery of messages, and so forth.
It also has the added benefit of being simple to implement.
Currently, I am thinking along these lines:
SERVER:
+ Main thread listens on a certain port. When a request comes in on that port, it spawns a WORKER to handle the request and goes back to listening. My thoughts on this: requests need to be grabbed quickly so the port isn't tied up. I know on a massive system this might cause lots of thread creates/deletes, but I rarely expect more than 1000 destinations, and maybe 5% are sending at once (high estimate IMHO), so that's 50 threads at most. I figure average rate is gonna be closer to 10 threads at most.
+ WORKER receives the data. Normally it is a send message request. (for heartbeat req see below) First step is to see if recipient is listed in the ACTIVE table; if so, it tries to deliver to the destination. If it succeeds, then all is well. If it fails, it drops the message into WAITING and also removes the destination from the ACTIVE table. If the destination is not listed in ACTIVE, it just immediately drops it into WAITING.
+ GARBAGE. Clients must send heartbeat every 15 minutes. Last heartbeat is entered into ACTIVE table. GARBAGE runs every 20 minutes, and any clients that have not sent heartbeat since 20 minutes are removed from the ACTIVE table. GARBAGE also ticks all messages in WAITING table; if a message receives more than X ticks (maybe 100,000?) it is considered orphaned and removed.
+ WORKER (heartbeat). If the data is a heartbeat signal, then worker just updates the last heartbeat field in ACTIVE and sends an OK response to the client.
+ WORKER (connect). When client connects, worker authenticates with whatever auth package admin has set, enters client into ACTIVE, then retrieves all messages for client that are in WAITING. Auth for starters it will be a USERS table, but i plan on having AD integration at some point
+ WORKER (disconnect). When client shuts down orderly, it sends disconnect. Worker removes client from ACTIVE table.
In this configuration, ACTIVE should have a relatively up-to-date picture of what destinations are currently reachable. WAITING stores all messages for clients that are not, to be delivered upon next connect.
Garbage ensures that you don't end up with undelivered messages in WAITING from 10 years ago causing the database to grow forever, and also ensures that if a destination goes offline suddenly without sending disconnect, it won't be stuck listed as 'online' forever.
I haven't quite worked out the best way to do the client yet... but it will probably be something like this:
This single-threaded app handles the UI and stuff. It also listens on the proper port. Whenever a server has a message for this destination, it will connect to this port to deliver it. The IP/port combo is listed in Active when client connects.
Received messages are posted where appropriate, and any messages to be sent are handled as needed.
Opinions? I think a setup like this would scale fairly well to a few thousand users at most, would allow for timely (yet disconnected) delivery of messages, and so forth.
It also has the added benefit of being simple to implement.