简体   繁体   English

调整php-fpm,nginx,mysql以获得EC2上的高流量

[英]Tuning php-fpm, nginx, mysql for high traffic on EC2

I'm looking to optimize my setup on EC2. 我想优化我在EC2上的设置。 CentOS 6, nginx 1.0.15, php 5.4.4 with php-fpm, xcache 2.0.0, mysql 5.5.24-55-log, redis 2.4.10, EC2 High Cpu XLarge (c1.xlarge 8 cores, 7G ram) for high traffic site, writes on every request. CentOS 6,nginx 1.0.15,带有PHP-FPM的PHP 5.4.4,xcache 2.0.0,mysql 5.5.24-55-log,redis 2.4.10,EC2 High Cpu XLarge(c1.xlarge 8核,7G ram)对于高流量的网站,会在每个请求上进行写。 Resulting web request is very small (javascript snippet). 产生的网络请求非常小(javascript代码段)。

Basically, it is a 100% dynamic environment (insert or update). 基本上,这是一个100%动态的环境(插入或更新)。 On every web request, I need to look in memcached for a quick lookup, then log a few attributes with every page request. 在每个Web请求上,我都需要在memcached中进行快速查找,然后在每个页面请求中记录一些属性。 I have several EC2s around the world helping to serve 600M+ requests per day. 我在世界各地有数个EC2,每天可帮助处理600M +个请求。 The idea is that I log the data and dump it hourly to be processed by some other machines. 我的想法是,我记录数据并每小时转储一次,以供其他计算机处理。 Each machine has been handling about 20M a day. 每台机器每天的处理量约为2000万。 I've tried a few data stores and some notes are as follows: 我尝试了一些数据存储,一些注意事项如下:

MySQL 的MySQL

  • using hourly tables to for the data so write to log_2012_09_05_11 exclusively for 9/5/2012 at the 11am hour. 使用小时表来存储数据,因此专门在9 am/2012的上午11点写入log_2012_09_05_11。
  • Using ephemeral storage 使用临时存储
  • MyISAM has proved to be faster than innodb for me. 对我来说,事实证明,MyISAM比innodb更快。 I've played with the buffer pool and I always seem to get better performance with myisam. 我玩过缓冲池,而myisam似乎总是能获得更好的性能。 Open to any suggestions on tuning here too, but the queries are fast. 也可以在此处进行任何有关调优的建议,但查询速度很快。 Myisam lock time are very tiny. Myisam锁定时间非常短。
  • I profiled the code using xdebug and under high load, 98% of the time was spent connecting to mysql. 我使用xdebug剖析了代码,在高负载下,98%的时间都花在了连接mysql上。 I was then able to get better performance by using persistent connections with mysqli. 然后,我可以通过使用与mysqli的持久连接来获得更好的性能。
  • Max ~2200 rps , get gateway timeouts and slow response afterward 最高〜2200 rps ,之后获得网关超时和较慢的响应
  • Server load max 1 or 2 (8 core machine) 服务器负载最大1或2(8核计算机)

Redis 雷迪斯

  • I really thought this would be awesome, but it seems like php is the bottleneck. 我真的以为这会很棒,但似乎php是瓶颈。
  • Max ~5-600 rps . 最高〜5-600 rps
  • This is with writing keys like this "log_2012_09_05_11_12345", with 12345 coming from a INCR counter by the hour. 这是通过编写类似“ log_2012_09_05_11_12345”的键来实现的,其中12345按小时来自INCR计数器。
  • Saving to disk once every 15 mins (operation took about 2mins if I remember correctly) 每15分钟保存一次到磁盘(如果我没记错的话,操作大约需要2分钟)

How many requests per second can I realistically expect out of this EC2 machine and 100% write scenario? 实际上,我每秒可以从这台EC2机器和100%的写入情况中期望多少个请求? Am I bound by EC2's disk performance or php or mysql? 我是否受EC2的磁盘性能或php或mysql的束缚? Can I configure it to use more CPU or better use the resources it's using? 我可以配置它使用更多的CPU还是更好地使用它正在使用的资源?

PHP-FPM http://pastebin.com/raw.php?i=9n2cpqrq PHP-FPM http://pastebin.com/raw.php?i=9n2cpqrq

NGINX (nginx.conf) http://pastebin.com/raw.php?i=XuVBKr8m NGINX(nginx.conf) http://pastebin.com/raw.php?i=XuVBKr8m

I really think you need to look into splitting out your architecture components onto different systems. 我真的认为您需要研究将架构组件拆分到不同的系统中。 For example, you noted that you are running MySQL on ephemeral storage. 例如,您注意到您在临时存储上运行MySQL。 This seems odd for MySQL in that your data could easily be lost. 对于MySQL来说,这很奇怪,因为您的数据很容易丢失。 Have you considered using Amazon RDS? 您是否考虑过使用Amazon RDS?

Also, instead of REDIS have you considering ElasticCache or SimpleDB for your Key-Value store. 同样,您可以考虑将ElasticCache或SimpleDB用作键值存储来代替REDIS。

I guess my main point is that, if you are dealing with the volume of requests that you are, you really should be breaking up your service stack into multiple tiers that can scale independently of each other. 我想我的主要观点是,如果您要处理的是大量请求,则实际上应该将服务堆栈分解为多个可以相互独立扩展的层。

One thing to mention with respect to performance, do not use EBS drives, unless as a RAID and with dedicated throughput. 关于性能的一件事,请不要使用EBS驱动器,除非作为RAID并具有专用吞吐量。 They really suck compared to ephemeral. 与短暂的相比,它们确实很烂。 I use hi1.4xlarge for database with its ephemeral drives on SSD. 我将hi1.4xlarge用于其SSD上的临时驱动器的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM