Home  >  Q&A  >  body text

mysql - 瞬间流量很高的网站,要频繁的插入数据到数据库,应该怎么解决这个问题?

瞬间流量很高的网站,要频繁的插入数据到数据库,怎么才能解决速度慢的问题?要用到什么技术?

PHP中文网PHP中文网2743 days ago759

reply all(7)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 15:17:45

    1. Distributed deployment of databases to increase instantaneous insertion performance
    2. If the business allows, use message queues for asynchronous insertion
    3. Use redis and the like for caching, and then insert asynchronously into the database
    3 . For data with frequent insertion operations and no need for related queries, you can choose to use a non-relational database such as mongo

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 15:17:45

    If the real-time requirements are not very high, you can use redis as a middle layer to receive data, and then use the background timing or message subscription mechanism to pull data from redis and write it into the database in batches.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 15:17:45

    1. Consider optimizing the storage structure 2. Consider multiple machines, multiple databases and multiple processes if possible. 3. Equipped with connection pool and middleware (message queue) and intermediate database (redis) 4. Multi-threading...

    reply
    0
  • 黄舟

    黄舟2017-04-17 15:17:45

    You can search for something like Taobao’s 140,000 orders per second as a reference. There is no hard and fast solution to this thing.
    To put it simply, it uses server-side cache such as redis to process requests.

    reply
    0
  • 迷茫

    迷茫2017-04-17 15:17:45

    You should also consider message queue

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 15:17:45

    You can try adding caching mechanism and doing load balancing

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 15:17:45

    1 Look at the logs to find the request address with too high requests. Find out the reason first to see if it can be avoided and whether it is a necessary operation
    2 Write a mysql trigger according to business needs and leave this work to mysql
    3 Use swoole to asynchronously insert into the database
    4 You can use multi-thread queue
    5 Do not write data directly to the database, you can write it to redis first

    reply
    0
  • Cancelreply