Table of Contents
回复内容:
Home Backend Development PHP Tutorial 如何优化网站高并发访问?

如何优化网站高并发访问?

Jun 17, 2016 am 08:31 AM

比如双11突发大流量

回复内容:

高并发访问,后台架构关键。

解决高并发访问,或者说改善,提高一点思路:
1.使用Squid或者Varnish做缓存代理,将经常访问的图片等静态内容缓存起来,提高访问速度;
2.使用CDN内容分发网络,减少主服务器的压力(附CDN相关内容:CDN通过在网络各处放置节点服务器所构成的在现有的互联网基础之上的一层智能虚拟网络,CDN系统能够实时地根据网络流量和各节点的连接、负载状况以及到用户的距离和响应时间等综合信息将用户的请求重新导向离用户最近);
3.使用LVS服务器负载均衡,LVS服务器结合Keepalived做高可用;
4.LVS下面还可跟Nginx做负载均衡,再次分担压力,比如淘宝使用的再Nginx基础上改进的Tnginx。
5.DNS服务器上也可下功夫,比如做高级视图等等,这样可以解决不同网段访问Web服务器的速度问题;
6.最大的瓶颈还是在IO上,比如存储IO,比如数据库的IO。存储一方面需要保证数据不丢失,另一方面需要保证性能,比如做RAID、LVM;存储还需要考虑使用一套存储之间的数据同步(GFS、OCFS可以实现),数据的备份等等;数据库的话可以考虑使用查询缓存等等,这块我也正在学习中,展开有很多东西;
7.程序的话也可以优化,比如如果是Java Web程序,并且使用了Hibernate框架,就可以考虑使用查询缓存了;
8.硬件层:比如提高带宽,购买高转数性能好的硬盘等等;

最后,就如@杨益提到的,淘宝支持那么大的并发量,并不是一蹴而就的,也是一步步走过来的,想想淘宝从什么时候成立,至今已发展多久就知道了。能把双十一撑下来,不得不佩服阿里在这方面所做的突破。

参考资料:内容分发网络_百度百科 这种问题 三言两语也说不清楚 毕竟业务不同 实际场景也不同
但是基础的思路都差不多 几乎都是一步步扩展和演变过来的
CDN 动静分离 缓存 负载均衡 高可用...几乎都离不开这些 补充 @温国兵的回答,刚刚这位大神已经从服务器架构层面回答的比较完善了。
我来说说具体服务端层面的高并发处理。
1.缓存机制,缓存机制的种类很多,有页面缓存(Squid),数据缓存(memcache),查询缓存,编译缓存(PHP是脚本语言在编译时有编译缓存).
2.数据库IO是最大问题,所以现在又了NOSQL的解决方案,首先将数据写入内存中,然后定时写入硬盘
3.程序优化,增加执行效率,用更好的算法等等。(采用分层,因为每个程序擅长处不一样,比如JAVA适合做中间层,C++做底层,现在又流行一种node.js做中间层,可以加强执行效率,多线程,以及一些安全问题)
4.队列系统,有些数据不要一来就马上处理,做个队列(先进先出),延迟处理。
如果回答不正确,请海涵,本人还在迷途中学习。 你这问题问得太大了,双11那种流量几乎没几个网站会碰到

泛泛而谈的话,其实就是找到瓶颈,优化之,找到新的瓶颈,继续优化之,如此循环反复。就连淘宝都是这么过来的

瓶颈在那里?
无状态好说,加机器各种缓存就ok。涉及到状态的scale up,scale out,适当作出某些牺牲例如一致性或者降级例如去掉确认收货点评等。

1 看来你已经有一个网站了,他是什么语言开发的?部署在什么环境里?有多少服务器?分别什么配置?
2 看来你遇到性能问题了,表现是什么?浏览器卡?死机?
3 “比如双11突发大流量”,没办法。做了这么多年双11活动了,还不是年年都被打死吗?解决这个问题唯一的办法是:双11涨价。

虽然我说技术是万能的,但是巨大的代价和每年都超预期的流量让所有人都措手不及。自己的网站优化要首先避免这个外部因素。然后技术的问题都不是问题。 ME:将js,css,img用云存储解决,WEB程序优化缓存、减化网站上功能设计上是好的实际使用中是没多大意思的功能,换固态硬盘,上好点的硬件 作为刚刚经历过双11的人,再补充一下。
其实网站技术就是那些,上面也说得比较清楚了。
我再补充一下,在双11之前都会有多轮的线上压测演练,对各个系统的性能能达到的QPS都已经摸得很清楚了。
然后根据以前的经验,会做出平时峰值接近10倍的服务器扩容。
还有各种降级预案,到关键时刻一个按钮就可以执行一堆降级功能。
到双11当天,有个大屏幕可以看到各个系统的水位(即当前QPS/极限QPS)
即便如此,一到12点,面对瞬间的巨量,每年仍然总会有几个系统当场瘫痪.... 中文的可以看看这本书---大型网站技术架构_核心原理与案例分析_李智慧 话题有点大
Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles