views:

116

answers:

3

I have a problem as follows:

Server process 1

  • Constantly sends updates that occur to a datastore

Server process 2

  • Clients contact the server, which queries the datastore, and returns a result

The thing is, the results that process 1 and process 2 are sending back the client are totally different and unrelated.

How does one decompose this? Do you just have one process constantly sending data, and define the protocol to have a bit which corresponds to whether the return type is 1 or 2?

Do you have two processes? How do they share the datastore then (it is just a structure not a database)?

Thanks!

A: 

Why not use a database instead of "just a structure"? Both relational and non-relational DBs offer many practical advantages (separate processes using them, take care of replication [[and/or snapshots, backups, ...]], rich functionality if you need it for the "queries", and so on, and so forth).

Worst case, the "just a structure" can be handled by a third process that's entirely dedicated to it (basically mimicking what any DB engine would offer -- though the engine would probably do it better and faster;-), allowing you to at least keep a good decomposition (with the two server processes both interacting with the "datastore process").

Alex Martelli
I was hoping nobody would grab onto that because I said "datastore". A database is very much unsuited to this application. Think of it like an array of ints, they are changing, a server has to send out their changes, the user can request some complicated calculation on the array.
DevDevDev
@Dev`*`3, whatever -- I still suggest you devote a process to the care and feeding of that store (thereby also intrinsically serializing access to it, a safe choice -- if you need some overlapping accesses you can then have fun implementing range locking, R vs W, and multithreading the datastore process;-).
Alex Martelli
+1  A: 

If you can restrict yourself to Twisted, I recommend to use Perspective Broker. It's essentially an RPC system, and doesn't care much about the notion of "client" and "server" - either the initiator of a TCP connection or the responder can start RPC calls in PB.

So server 1 would accept registration calls with a callback object, and call the callback whenever it has new data available. Server 2 provides various RPC operations as clients require them. If they operate on the very same data, I would put both servers into a single process.

Martin v. Löwis
And just store the data as a processwide global variable? That is more or less the road I am going down right now using Twisted. Can you point me to an example of using callbacks over a network? Wouldn't the client then have to act as an RPC server as well?Right now I am doing just what you said except the client has two threads, one just blocks on receiving data from Server 1, and the second is available to send RPC calls to server 2.
DevDevDev
I can only use Twisted on the server side, does this limit me to using straight TCP?
DevDevDev
@DevDevDev: To get a real world example of PB, take a look at the buildbot (buildbot.net). The build slaves log into the master; then RPCs go in both directions over a single TCP connection (allowing to call into slaves that live behind a firewall or NAT). If the clients are not written in Python, you have to roll your own RPC protocol over TCP. I recommend to use a TLV encoding.
Martin v. Löwis
+1  A: 

It sounds like you want to stream your series of ints "somewhere" and also collect them in a datastore. In my system I am streaming sensor readings into a database and also allowing them to go directly to web clients, giving them live power readings. I've written a blog entry on why a database is not suitable for live data - though it is perfect for saving the data for later analysis.

I'd have the first server process be a twisted server that uses txamp to stream the ints to RabbitMQ. Any clients that want live data can subscribe to the stream in RabbitMQ, also using Txamp. Web browser clients can use Orbited here is a worked example.

In your design server 1 saves to the database. You could instead have server3 collect data from RabbitMQ and stream it to the database. I plan to have a server that collects chunks of data and render graphs to store to a central fileshare.

Don't create your own messaging system, RabbitMQ is well tested, scalable, and can persist your "messages" (raw data) if something goes wrong.

Tom Leys
That was what I initially thought, but there is no robust STOMP client that runs natively on the iPhone.
DevDevDev
You don't need a STOMP library if you are working natively on iphone, what you want then is a C++ AMQP client library, like txAMP is a library for python. Do some googling to find one you like.
Tom Leys