Mysql db as an alternative to socket programming?

Is it wrong to use the mysql database on some remote server as a means of interaction between two remote computers? For example, having box1 polled in a certain line of the remote db check for the values ​​sent by box2, when box2 sends some value to box1, it does a, b, c. Thanks for any advice.

+4
source share
4 answers

Consider using something like ZeroMQ , which is an easy-to-use abstraction over sockets with mounts for most languages. There is some good intro documentation , as well as many examples of various templates that you can use in your application.

I can understand the temptation to use a database for this, but the idea of ​​constantly writing / polling is simply to signal IO waste between clients, connect communications, etc., and more importantly, it would seem difficult to understand / debug another person (or myself in two years).

+4
source

You can. If you are building something complicated, I would caution against this, but it’s fine - you need to deal with the fact that things are done only once, but it’s not so difficult.

What you do is called a message queue, and there are open source projects for it, including some based on MySql.

+3
source

Yes?

You confuse the point of your code by putting an intermediary in a situation. You seem to be trying to use what you know to do what you don't know. This is pretty normal, because then the problem seems to be solvable.

+3
source

If there are only 2 computers (sender-receiver), then this is bad practice if a fast response time is required. Otherwise, this is normal ... a direct socket connection would be better, but don't waste time on it unless you really need it.

On the other hand, if there are more than two machines and / or you need fault tolerance, then you really need an intermediary. Depending on the signaling you want between the machines, the intermediary may be a simple keystore (for example: memcached, redis) or a message queue (for example: a special program for the message queue, but I saw that MySQL is used as a queue in two different sites with high traffic)

+1
source

Source: https://habr.com/ru/post/1347290/


All Articles