PHP large traffic optimization?

Source: Internet
Author: User
Tags solr mysql slow query log
The basic idea of our technical group is that all PHP and mysql are decoupled from each other and added to the cache layer. for example, if a member registers, the database is written to the server memory and then written to the database at the same time. which technologies will be used? I have never touched this problem. now, the website traffic is greatly increased. The basic idea of our technical group is that all PHP and mysql are decoupled from each other and added to the cache layer. for example, the member registration is first written into the server memory and then unified. write data to the database at the same time. Which of the following technologies will be used in the cache layer: if you think that mysql reading and writing is a bottleneck (mysql Query and writing takes a long time, or the magnitude is large), you can indeed introduce the intermediate cache.
We recommend that you use redis as the intermediate cache service to build a cache between mysql and PHP.

However, you still need to analyze why it takes a long time to read and write mysql to solve your system problems. you can enable mysql slow query log analysis.
If there is a problem with reading and writing, you can try these steps:
(1) is the SQL statement reasonable? is there too many table join operations?
(2) are there too many table records and millions of data records required for database/table sharding or partitioning?
(3) are appropriate indexes used and SQL query statements fully utilize index fields?
(4) you can adjust mysql configuration parameters to optimize mysql read and write performance, such as increasing innodb_buffer_pool_size and increasing the cache hit rate.
(5) for a single mysql deployment, you can consider master-slave separation or set up master-slave mutual backup.
......

If you think that mysql still has some bottlenecks after the above optimization, it is not too late to introduce redis as the intermediate cache.

In fact, I wrote only the tip of the iceberg, and there is also a lot of Doha to be optimized.
An earlier article:
Construction of hundreds of millions of Web systems-standalone to distributed clusters Optimization is not difficult, but the right remedy is needed.

Subject, your problem description, no symptoms, no reason found, jump directly to the development of a treatment plan: [all PHP and mysql decoupling ...... ], this is really good? I am here to pay attention to the problem,... Now most of the memory cache is optimized for reading... What is the write optimization solution ???

I am actually concerned about the problem .. We should first find out the crux of the problem, rather than blindly optimizing it.

A common cause of slow system write speed is usually the frequent write count scenario. for example, if the pv field is + 1, each page is accessed, frequent writes cause the query cache of MySQL to become invalid immediately upon creation, which is equivalent to ineffective. This situation is suitable for creating a buffer (with extremely frequent writes and no data consistency requirements) to store new PVS. when the buffer zone is full, write data at a time.

You said," All PHP and mysql are decoupled from each other and added to the cache layer."Not very good. In most cases, what you call the cache layer is to take over the query cache function of mysql, which is of little significance. Moreover, important data such as registration is not suitable for caching. Once the cache is lost, it is troublesome. The middle layer you mentioned is called a queue. you can use the redis list to optimize the business logic of reading and writing MySQL first. the member registration function needs to be cached, so how slow it is to run, and your data is suspended in the cache, isn't it? I'm not kidding.
The cache is optimized for reading and writing data. 1. cache
Plan the change frequency and read/write frequency of the target data.
Read/write frequency: the larger the change frequency value, the more suitable it is for caching.

2. optimize SQL
Most of the primary systems do not have a high degree of SQL optimization ......
Use of indexes, whether a single query is too large, and replace a joined table query with a single table query
Replace MYISAM with INNODB ......

3. optimize the system architecture
Is there too much content in a single page and unnecessary data display?
Can we split a lot of functions into different business modules and present them separately?

4. static page
Static pages consume much less than dynamic pages.

5. delayed reading of cached data
Write queue and cache temporary data (such as counters) all belong to this type

6. obtain data asynchronously

7. distributed architecture
Read and write separation of databases. read this article from multiple database servers or even multiple PHP servers:
Edited on February 7,. sometimes the bottleneck is not necessarily in the database. First, check whether it is a front-end or a backend problem. If it is a front-end, various optimizations should be done, including caching static files, merging and compressing css, js and other files, and minimizing HTTP requests. If the read/write performance of the backend database is faulty, perform Profiling to locate the bottleneck. If you want to add a cache layer, we recommend using Redis to support data persistence. In addition, message queues can be considered for asynchronous communication to achieve program decoupling. Message Queue can cope with sudden peak traffic. I personally recommend RabbitMQ, which is also used by our company. In addition, you can use an independent full-text search engine to reduce the search pressure on the database. Solr and ElasticSearch are both easy to use. I use Solr myself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.