search

现在网站流量大幅上升 我们技术组基本的思路是 所有的PHP与mysql脱钩 中间加入缓存层 比如会员报名先写入服务器内存 然后统一的时间一起写入数据库 请问中间的缓存层会用到哪些技术 对这个重来没有接触过

回复内容:

如果是觉得mysql的读和写是瓶颈的话(mysql的查询和写入耗时很长,或者量级比较大),的确可以引入中间缓存。
搭建mysql和PHP之间的缓存,推荐直接使用redis作为中间缓存服务。

不过,还是需要分析下为什么是mysql的读和写耗时很长,才能够真正解决你系统的问题,可以开启mysql的慢查询日志分析下。
读和写如果有问题,可以往这几个方面做下尝试:
(1)sql语句是不是合理的,是否带有太多的表join等操作?
(2)table的记录是否太多了,好几百万的数据,是否需要分库分表或者分区?
(3)是否使用了合适的索引,sql查询语句是否有充分利用索引字段?
(4)可以通过调整mysql配置参数,来优化mysql读和写的性能,例如增大innodb_buffer_pool_size,提高缓存的命中率等。
(5)mysql如果是单台部署,可以考虑主从分离,或者搭建主主互备。
... ...

如果觉得mysql在上述优化之后,仍然存在一些瓶颈,再引入redis作为中间cache也并不迟。

其实,我上面写的只是冰山一角,可以优化的地方还有非常多哈。
早期写的一篇文章:
亿级Web系统搭建――单机到分布式集群 优化不难,但需要对症下药。

题主,你的问题描述,没说症状,没查病因,就直接跳跃到制定治疗方案:【所有的PHP与mysql脱钩......】,这真的好? 我是来关注问题的,不过。。。现在大部分内存缓存都是对读做优化的。。。对写优化的解决方案???

我其实是来关注问题的。。 先应该找出症结,而不应该盲目优化。

常见的写入引起系统速度慢通常是计数这种频繁写入的场景,比如:每访问页面一次,pv字段+1,频繁写入导致MySQL的查询缓存刚创建就马上失效,相当于没发挥作用。这种情况是很适合搞个缓冲区(写入极频繁、无数据一致性要求),来存放新增的pv的,当缓冲区满了,再一次性写入。

你说的“所有的PHP与mysql脱钩 中间加入缓存层”就不太好,其实大部分情况下你所谓的缓存层不过是把mysql的查询缓存功能废了自己接管,意义不大。而且像报名这种重要的数据也不适合缓存,一旦缓存丢失,比较麻烦。 你说的这个中间层 叫队列,可以用redis的list去做 最好还是先优化一下读写MySQL的业务逻辑,会员注册报名这种功能都需要加缓存了,那跑起来得多慢 缓存挂了你这数据难道不要了?不是在开玩笑吧。
缓存优化的是读,写数据不要走这邪路。 1.缓存
规划下目标数据的更改频率和读写频率。
读写频率:更改频率 值越大,越适合做缓存;值小的就别做了

2.优化SQL
大部分的初级系统的SQL 优化程度都不高……
索引的使用、单一查询是否过大、联表查询替换为单表查询
MYISAM替换为INNODB 这类的……

3.优化系统架构
单一页面中涉及的内容是否太多,是否有不必要的数据展示
能否将很多的功能与系统拆分成不同的业务模块 分开展示

4.静态化页面
静态页面比起动态页面来自然会消耗小的多

5.缓存数据延时读取
写入队列、缓存暂存数据(比如计数器) 都属于这种

6.异步式获取数据

7.分布式架构
数据库的读写分离 , 多台数据库服务器 乃至 多台PHP服务器 等 读这篇,全部读懂再说:
编辑于 2014-05-07 有时候的瓶颈不一定在数据库,先搞清楚是前端还是后端问题。如果是前端就要做各种优化处理,包括缓存静态文件,合并并且压缩css, js等文件,尽量减少HTTP request等等。如果是后端数据库读写性能问题就先做下Profiling找下瓶颈在哪。如果真的是要加缓存层建议用Redis, 支持数据持久化。另外可以考虑消息队列异步处理通信,达到程序解耦的目的。消息队列可以很好地应付 突然的峰值流量,个人推荐RabbitMQ,我们公司也在用。还有就是可以使用独立的全文搜索引擎,降低数据库的搜索压力,Solr, ElasticSearch都好用,我自己用的是Solr。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool