S
S
Sergey Zabirnikov2016-07-31 14:21:32
MySQL
Sergey Zabirnikov, 2016-07-31 14:21:32

Persistent mysql connection or how to keep the connection?

The task is this: you need to get one record from the database, then send a request to the address obtained from the database record and get the necessary data, then write it to the database and repeat the procedure.
To be honest, I have a problem with the implementation on nodejs. In any other language (php, go, etc.) such problems would not have arisen, but here.
Keeping a permanent connection to mysql is impossible due to the settings and the very architecture of mysql. Creating a pool and creating a new connection each time is not a good idea (or does anyone have a different opinion?).
What is the best way to implement this task on nodejs? Or is it better to switch to go for such tasks?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Mylchenko, 2016-08-04
@ERrorMAKros

When I encountered this problem (not on nodejs, but on java), the reason was that if the connection does not transfer data for about 15 minutes - the MySQL server forcibly disconnects the connection with the client, although the client does not catch any events about this until then until it starts transmitting data - and at this moment we catch an exeption that there is no connection. Even the MySQL option MYSQL_OPT_RECONNECT doesn't work...
I got out of the next. Thus - from the moment of the first successful connection to MySQL, every 5 minutes (in a timer) the client sent an empty query to the database (SELECT 1) - this helped to maintain the connection - MySQL server reset the user's timeout timer and one connection could be maintained for months!

V
Vladimir Grabko, 2016-07-31
@VGrabko

a pool of connections and a thread that checks connections from time to time and recreates them if necessary. This is how it works everywhere. I don't know about node.
UPD.
Did you do a pull in Go that stored the pull ? ahah

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question