If the number of database connections is only 1000, how to deal with the concurrency of 1 million? You can't use load balancing. Is there any other way?

ask the bosses for an idea. This is my interview question in the morning.


1. Use redis to store high frequency query data. Improve query speed
2, mysql master and slave
3, add, delete, modify and add queue
4, cut table library
5, swoole solve concurrency
6, if necessary, use grpc for service governance
7, micro service
8, code segmentation
. Wait

is another process of interviewing for building a nuclear bomb and screwing at work


first correct you, load balancing has nothing to do with your problem. Secondly, your question is also very interesting, because this kind of scene is very difficult to appear. However, I still pretend that you have really encountered this extremely unbalanced situation.
1. Make good use of redis, to intercept a large number of request tools in the redis layer
2. Introduce connection pool middleware. Connection pooling and mysql are long connections, so you don't have to worry about the performance problems caused by frequent handshakes. The program takes a link handle from the connection pool and puts it back quickly after use. I can withstand it for a while.
besides, I don't know what silver bullet has changed


space for time, caching commonly used tables in memory.


database really has nothing to do with load balancing. The first is the message queue, the master-slave architecture of the database. It's just 1 million concurrency. I think it's usually about network access rather than the number of database connections. 1 million concurrency without load balancing. I really don't know how your single server can handle this traffic. Even if the bandwidth is large enough, I don't think the user experience will be very high.


  1. cache, you don't have to go to the database
  2. message queue, which can be limited to the number of databases to relieve pressure
  3. connection pool management, multiplexing connections, waiting for management.
  4. Database optimization, read and write optimization, improve the efficiency of the database.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e58c41-43a88.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e58c41-43a88.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?