M
M
MalyshevDmitry2013-12-20 14:48:46
MySQL
MalyshevDmitry, 2013-12-20 14:48:46

How to work with several MySQL servers from under Node.JS at the same time?

Good afternoon.
There is a mobile project. Social network. All data is stored in MySQL, divided into logical shards. We store "hot data" in Redis, we also store the MySQL shard map there.
The back-end is written in node.js (express)
Interested in how you can quickly access different MySQL servers as part of processing one request to the back-end?
I'll give you an example.
The client accesses the back-end with a request for a user profile with id = 1, which we store on the mysql-1 server in shard #1. At the same moment, another client accesses the back-end with a request for a user profile with id = 2, which is stored on another server - mysql-2 in shard #2.
The number of mysql servers will grow. And the number of requests to the back-end will grow. Initializing a new connection to MySQL for each request to the back-end is probably not the best task.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2013-12-20
@k12th

Perhaps a stupid question: why not create separate connections to each server/shard at application startup?

A
AxisPod, 2013-12-20
@AxisPod

Look in the direction of the connection pool, to raise the connection every time, a rather expensive operation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question