Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Design question: handling hundreds of state machines in a Web context

by Corion (Pope)
on Jan 02, 2013 at 16:36 UTC ( #1011314=note: print w/replies, xml ) Need Help??

in reply to Design question: handling hundreds of state machines in a Web context

You'll need to specify in more detail what you mean by accuracy. I assume that "accuracy" relates to the workflow(s) in progress, that is, the state of each state machine. Personally, I would at least write a continous log of each state change of each machine to be able to easily replay/restore a crashed session. Personally, I'm really fond of pushing the problem of keeping (shared) state to a database, so I would at least store the state and possibly also the log of the transition(s) of each state machine in database tables.

One system that sounds a bit like what you're doing is Deliantra, a MORPG written by Marc Lehmann, the author of AnyEvent (among other things). I think it supports a fairly large number of clients and think its overall architecture is likely worth investigating.

  • Comment on Re: Design question: handling hundreds of state machines in a Web context

Replies are listed 'Best First'.
Re^2: Design question: handling hundreds of state machines in a Web context
by Anonymous Monk on Jan 02, 2013 at 16:47 UTC

    "Accuracy" means that if a machine should move from state A to state B, that transition takes place.

      Sure, but at what point do you accept the legal responsibility for the transition with regards to your customer, and how will you handle recovery? Is it OK to replay (a series of) transitions if you keep the state in memory and write the state to disk every five minutes, while keeping a transition log? Do you want/need two-phase commit, where you send a confirmation for each processed transition?

      How consistent needs the overall state of the system to be? Is it OK if all transitions for client A were processed but only the first half of the transitions for client B were processed? What if A and B own ultiple machines? What is the processing order of the transitions? Is it OK to process transitions in parallel across different threads? Is it OK to reorder transitions for a single state machine? Can a transition be cancelled or can it time out?

      Most of these guarantees should be answered by a proper messaging system, like IBM MQSeries or maybe ZeroMQ nowadays, or alternatively by having all clients write directly to a database. I think you will need one, but I don't have much experience with the advantages or disadvantages of such queue systems.

        There is no legal responsibility, but our reputation is at stake. Each "client" is a Web browser, so it doesn't matter if they have multiple machines as we handle the transitions on the server side. The clients won't be logged in multiple times on different machines for the same user context and if they do, they understand there are no guarantees and that they're not supposed to do that. In other words, each user's context can be considered a single-threaded process and each transition happens sequentially, but the state is maintained across HTTP requests.

        A transition, once it is triggered, should not be cancelleable or timed out.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011314]
[hippo]: That's some Joycean spam.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2018-05-22 12:26 GMT
Find Nodes?
    Voting Booth?