What are the pros and cons of using database for IPC to share data instead of message passing?
Asked Answered
P

2

6

To be more specific for my application: the shared data are mostly persistent data such as monitoring status, configurations -- not more than few hundreds of items, and are updated and read frequently but no more than 1 or 2Hz. The processes are local to each other on the same machine.

EDIT 1: more info - Processes are expected to poll on a set of data they are interested in (ie. monitoring) Most of the data are persistent during the lifetime of the program but some (eg. configs) are required to be restored after software restart. Data are updated by the owner only (assume one owner for each data) Number of processes are small too (not more than 10)

Although using a database is notably more reliable and scalable, it always seems to me it is kind of an overkill or too heavy to use when all I do with it is to share data within an application. Whereas message passing with eg. JMS also has the middleware part, but it is more lightweight and has a more natural or flexible communication API. Implementing event notification and command pattern is also easier with messaging I think.

It will be of great help if anyone can give me an example of what circumstance would one be more preferable to the other.

For example I know we can more readily share persistent data between processes using database, although it is also doable with messaging by distributing across processes and/or storing with some XML files.

And according to here, http://en.wikipedia.org/wiki/Database-as-IPC and here, http://tripatlas.com/Database_as_an_IPC. It says it'd be an anti pattern when used in place of message passing, but it does not elaborate on eg. how bad can the performance hit be using database compared to message passing.

I have gone thru several previous posts that asked a similar question but I am hoping to find an answer that'd focus on design justification. But from those questions that I have read so far I can see a lot of people did use database for IPC (or implemented message queue with database)

Thanks!

Pathoneurosis answered 4/2, 2011 at 9:55 Comment(3)
For one, if you use a database, you'll have to resort to polling it for new messages. You have to decide how much of a problem this is (e.g. does it consume significant resources? max allowed connections might be an issue).Livorno
Thanks. Processes are expected to poll on a set of data they are interested in (ie. monitoring) And most of the data are persistent and updated by the owner only (assume one owner for each data) Number of processes are small too (not more than 10)Pathoneurosis
The second link is now a 404...Kimbro
T
5

I once wrote a data acquisition system that ran on about 20 lab computers. All the communication between the machines took place through small tables on a MySQL database. This scheme worked great, and as the years went by and the system expanded everything scaled well and remained very responsive. It was easy to add features and fix bugs. You could debug it easily because all the message passing was easy to tap into.

What the database does for you is that it provides a fast, well debugged way of maintaining concurrency while the network traffic gets very busy. Someone at MySQL spent a lot of time making the network stuff work well under high load, and if you write your own system using tcp/ip sockets you're going to be re-inventing those wheels at great expense of time and effort.

Another advantage is that if you're using the database anyway for actual data storage then you don't have to add anything else to your system. You keep the possible points of failure to a minimum.

So all these people who say IPC through databases is bad aren't always right.

Tetragonal answered 30/9, 2019 at 5:20 Comment(1)
Plural of anecdote is not data: the fact that one implementation (yours) seem to work, does not prove in general that it is a not bad idea.Kimbro
F
4

Taking into account that DBMS is a way to store information, and messages are the way to transport information, your decision should be based on the answer to the question: "do I need persistence of data in time or the data is consumed by recipient".

Fraga answered 4/2, 2011 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.