Summary of High Performance

《构建高性能web站点》总结:

 


 

网络(Network):
1. 优化链路层(Optimize the data link control)
2. 减少传播的数据量(Reduce your bytes)
3. 减少数据间的传播距离,分布式的数据中心(Reduce transmission distance)
4. 增加带宽,并作优化,还要采取适当的限制措施(Enlarge, optimize, restrict your bandwidth).
5. 适当的重发机制(Resend properly)

 


 

服务器(Server):
1. 经常进行压力测试,如 Apache AB (Pressure testing)
2. 更多的CPU,更多进程,优化进程调度(More CPU and more process, but not threads, optimize process switch).
3. 时刻观察系统负载(Observe load average)
4. 减少锁的使用,如文件锁,表所,行锁,日志锁等等(Reduce locks (file lock, table lock, row lock, log lock etc.).
5. 预先计划好内存分配(Manage your memory pool).
6. 尽量使用异步,非阻塞I/O模型的产品,如 Nginx(Server that with asynchronous and non-blocking I/O).
7. 适当的长连接,甚至不要长连接(Few or non keep-alive connection)

 


 

缓存(Caching)
1. 页面静态化缓存,如 Smarty (Page cache)
2. 数据和对象(内存)缓存,如 APC,XCache(Data and object memory cache)
3. 服务器缓存,如 Memcached,Redis (Server cache)
4. 动态页面(局部)静态化,如一般 CMS 所做的那样(Staticize dynamic pages)
5. Apache 缓存,如 Apache mod_cache mod_disk_cache mod_file_cache (Server side caching)
6. 服务器端包含 SSI, mod_ssi, shtml pages(Server side include)
7. 反向代理缓存,Apache mod_proxy,Nginx proxy_pass (Reverse proxy cache)

 


 

动态脚本(Dynamic Script)
1. 脚本中间码缓存,如 APC,eAccelerator,XCache 等等(Opcode caching)
2. 尽量减少拓展模块的使用(Enable those exts we really need)
3. 脚本跟踪与分析,如 PHP 的 XDebug,XHProf 等(Trace and profile the scripts)

 


 

浏览器(Browser)
1. 最后修改时间,暗示本地缓存(Last-Modified / If-Modified-Since / 304 Not Modified)
2. 编码标记,协商本地缓存(ETag / If-None-Match / 304 Not Modified)
3. 缓存截止期,明确何时过期(Expires & Cache-Control)
4. 彻底消灭请求(RFC2616: The goal of caching in HTTP/1.1 is to eliminate the need to send requests in many cases)

 


 

Web组件(Web Components)
1. 分离你的web组件,例如 img.kimbs.cn, js.kimbs.cn, upload.kimbs.cn etc. (Separates web components).
2. 正确配置 cookie 及其作用域(Cookie and it’s domain)

 


 

分布式缓存(Distributed Cache)
1. 使用分布式 Memcached 群组(Memcached group)
2. 写操作缓存,原子加法(Written caching and atomic addition)
3. 分组与哈希(Grouping and hash)

 


 

数据库查询(Database Queries)
1. 使用正确的索引,MySQL 命令及语句 “where, order by”(Use the right index)
2. 正确的组合索引(Composite index)
3. 如果是MySQL,多用 explain,mysqlreport 等工具(MySQL explain, mysqlreport etc.)
4. 查询缓存(Queries cache)
5. 提供行锁的 InnoDB 在大多数情况比较优秀(Row lock, InnoDB vs others)
6. 反范式设计,如 MongoDB, MemcacheDB, CouchDB etc.(NoSQL)

 


 

负载均衡(Load Balancing)
1. 通过代码,实现 Http 重定向(Http redirect,RR strategy)
2. 用 DNS 实现重定向,智能解析,故障转移(DNS redirect,”A” record, CNAME,Intelligent analytical,failover)
3. 反向代理,如 Nginx upstream,HAProxy(Reverse proxy, nginx ip_hash|upstream|weight)
4. IP 负载均衡,DNAT,IPVS(Ip load balance)
5. 将实际服务接入外部网络,LVS-DR(Online backend servers)

 


 

文件共享(File Sharing)
1. 使用 NFS 实现文件共享,基于 RPC 协议(File sharing with NFS)
2. Samba 实现 windows 和 linux 文件共享(Samba between linux and windows)

 


 

文件同步(File Sync)
1. 基于 SSH,如 SCP 和 SFTP(SCP and SFTP based on SSH)
2. 使用 Http 拓展协议 WebDAV,如 subversion(Use WebDAV)
3. 使用 Rsync (Use rsync)

 


 

分布式文件系统(Distributed File System)
1. MogileFS
2. Hadoop

 


 

数据库拓展(Database Expand)
1. 主从复制实现读写分离(Slave/master, reading and writing separation)
2. 数据库反向代理,如 MySQL Proxy(Database reverse proxy)
3. 垂直分区(Vrtical partitioning)
4. 水平分区,哈希规则(Sharding and hash)

 


 

分布式计算(Distributed Computation)
1. 消息队列,如 Gearman,MemcacheQ(Message queue )
2. 并行计算,Map/Reduce(Parallel computing and Map/Reduce)

 


 

性能监控(Monitor)
1. Cacti
2. MRTG

Posted in Optimization, Project Management | Leave a comment