简体   繁体   English

Amazon Linux EC2 Webserver / MYSQL升级 - 导致错误建立数据库连接的流量

[英]Amazon Linux EC2 Webserver / MYSQL Upgrade – Traffic causing error establishing a database connection

To give you a little background, I currently have a website that allows users to upload photos. 为了给你一点背景,我目前有一个网站,允许用户上传照片。 The website was initially on a GoDaddy shared server, but recent surges in traffic have forced me to explore other options. 该网站最初是在GoDaddy共享服务器上,但最近的流量激增迫使我探索其他选项。 During peak hours, the site contains 400+ active visitors, which when combined with user uploads, forces the shared server to shut down. 在高峰时段,该站点包含400多个活动访问者,当与用户上载相结合时,会强制共享服务器关闭。

I have a small amount of experience with setting up servers through AWS and attempted to place the website on a c1.medium instance, Amazon Linux. 我在通过AWS设置服务器方面有一些经验,并试图将网站放在c1.medium实例Amazon Linux上。 The website along with the MYSQL Database is on the same instance. 该网站与MYSQL数据库位于同一实例中。 While I have read that this is in general frowned upon, I have similarly read that moving the database to another instance would not significantly increase speeds. 虽然我已经读到这通常不赞成,但我已经同样读到将数据库移动到另一个实例不会显着提高速度。 Unfortunately, the c1.medium instance also was unable to support the traffic and I soon received an error Establishing a Database connection. 不幸的是,c1.medium实例也无法支持流量,我很快收到错误建立数据库连接。 The site does load on occasion, so the problem stems from the traffic load and not an actual problem with the database. 该网站有时会加载,因此问题源于流量负载而不是数据库的实际问题。

My question is whether the problem revolves solely around MySQL? 我的问题是问题是围绕MySQL进行的吗? The database itself when backed up is around 250MB. 备份时数据库本身大约为250MB。 Is the issue caused by input / output requests to the database? 问题是由对数据库的输入/输出请求引起的吗? I read posts with people with similar problems in which they stated that installing MySQL 5.6 solved the problem, but also have read that MySQL 5.6 is slower than MySQL 5.5, which is my current version. 我读过有类似问题的人发帖,他们说安装MySQL 5.6解决了这个问题,但也读过MySQL 5.6比MySQL 5.5慢,这是我目前的版本。

After conducting some preliminary research I started to believe that I could resolve the problem by increasing the IPOS of the EBS. 在进行一些初步研究后,我开始相信我可以通过增加EBS的IPOS来解决问题。 Originally I had it set the IPOS as standard, but changed it to Provisioned IOPS and 30x the size of the EBS (ie, 60GB – 1800 IOPS). 最初我把IPOS设置为标准,但是将其更改为预配置IOPS和EBS大小的30倍(即60GB - 1800 IOPS)。 This once again appeared to have little impact. 这再一次似乎没什么影响。 Do I need to upgrade my instance? 我需要升级我的实例吗? What measures should I be focused on when deciding on the instance? 在决定实例时,我应该关注哪些措施? It appears that the cheapest instance with high network performance and EBS optimized would be c3.xlarge. 看来,具有高网络性能和EBS优化的最便宜的实例将是c3.xlarge。 Suggestions? 建议?

Several things to consider: 需要考虑的几件事:

1)Separate the database server from the web server 1)将数据库服务器与Web服务器分开

Your database should not share resources with your web server. 您的数据库不应与您的Web服务器共享资源。 They will both perform poorly as the result. 结果他们都表现不佳。 It is easier to find what the bottle-neck is. 更容易找到瓶颈是什么。

2) Upgrade to MySQL 5.6 2)升级到MySQL 5.6

In all the benchmarks that I have seen and done 5.6 performs better than 5.5 在我看过和完成的所有基准测试中,5.6的性能优于5.5

3) Configure your database to take advantage of your resources 3)配置数据库以利用您的资源

Depending on the storage engine and the memory allocated in your machine configure MySQL for example set innodb_buffer_pool_size to 70% of the (DEDICATED) RAM 根据存储引擎和机器中分配的内存,配置MySQL,例如将innodb_buffer_pool_size设置为(DEDICATED)RAM的 70%

4) Monitor MySQL and check slow query log 4)监控MySQL并检查慢查询日志

Slow query log shows the queries that are slow and inefficient 慢查询日志显示缓慢且低效的查询

5) Learn to use EXPLAIN 5)学习使用EXPLAIN

EXPLAIN shows query plan in MySQL run EXPLAIN on slow queries to tune them EXPLAIN显示MySQL中的查询计划在慢速查询中运行EXPLAIN来调整它们

6) Use Key-Value Stores to Cache queries 6)使用键值存储来缓存查询

Using Memcached or Redis cache queries so they don't hit your database and return repeated queries from the memory 使用Memcached或Redis缓存查询,以便它们不会访问您的数据库并从内存中返回重复的查询

7) Increasing IOPS and Scaling Out 7)增加IOPS和扩展

Increasing IOPS and getting better hardware helps but using efficient queries is much more effective. 增加IOPS并获得更好的硬件有助于提高效率,但使用高效查询会更有效。 Queries and application most of the time are a greater contributing factor to performance problems 大多数情况下,查询和应用程序是导致性能问题的更大因素

8) Replication 8)复制

To help with concurrency consider moving to a MySQL Master/Slave replication , if you still had issues. 如果仍有问题,请考虑转向MySQL主/从复制。

Final Note: use EBS because the storage on EC2 is ephemeral and will not persistent. 最后注意:使用EBS是因为EC2上的存储是短暂的并且不会持久存在。

We recently did extensive research on the performance bottlenecks associated with massive end-user peaks across our global customer base, and the analysis actually indicates the database as - by far - the most frequent cause of slowdowns or even crashes. 我们最近对与全球客户群中的大量最终用户峰值相关的性能瓶颈进行了广泛的研究,并且分析实际上表明数据库 - 迄今为止 - 是导致速度减慢甚至崩溃的最常见原因。 The report ( https://queue-it.com/trend-report ) includes best practice advice from our customers on how to improve the situation, which you may find helpful. 该报告( https://queue-it.com/trend-report )包含了客户关于如何改善情况的最佳实践建议,您可能会发现这些建议很有帮助。

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

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