CPU 사용률 LAMP 스택

CPU 사용률 LAMP 스택

Magento(centos 5.6, httpd 2.2, php 5.2.17, eaccelerator 0.9.5.3, mysql 5.1.52)를 실행하는 ec2 m2.4xlarge가 있습니다. 현재 트래픽이 크게 급증하고 있으며 상단은 다음과 같습니다.

top - 09:41:29 up 31 days,  1:12,  1 user,  load average: 120.01, 129.03, 113.23
Tasks: 1190 total,  18 running, 1172 sleeping,   0 stopped,   0 zombie
Cpu(s): 97.3%us,  1.8%sy,  0.0%ni,  0.5%id,  0.0%wa,  0.0%hi,  0.0%si,  0.4%st
Mem:  71687720k total, 36898928k used, 34788792k free,    49692k buffers
Swap: 880737784k total,        0k used, 880737784k free,  1586524k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2433 mysql     15   0 23.6g 4.5g 7112 S 564.7  6.6  33607:34 mysqld
24046 apache    16   0  411m  65m  28m S 26.4  0.1   0:09.05 httpd
24360 apache    15   0  410m  60m  25m S 26.4  0.1   0:03.65 httpd
24993 apache    16   0  410m  57m  21m S 26.1  0.1   0:01.41 httpd
24838 apache    16   0  428m  74m  20m S 24.8  0.1   0:02.37 httpd
24359 apache    16   0  411m  62m  26m R 22.3  0.1   0:08.12 httpd
23850 apache    15   0  411m  64m  27m S 16.8  0.1   0:14.54 httpd
25229 apache    16   0  404m  46m  17m R 10.2  0.1   0:00.71 httpd
14594 apache    15   0  404m  63m  34m S  8.4  0.1   1:10.26 httpd
24955 apache    16   0  404m  50m  21m R  8.4  0.1   0:01.66 httpd
24313 apache    16   0  399m  46m  22m R  8.1  0.1   0:02.30 httpd
25119 apache    16   0  411m  59m  23m S  6.8  0.1   0:01.45 httpd

질문:

  • msyqld에 더 많은 메모리를 제공하면 쿼리를 캐시하고 더 빠르게 반응하는 데 도움이 됩니까?
  • 그렇다면 어떻게?
  • mysql과 php를 별도의 서버로 분할하는 것(우리가 곧 수행할 작업) 외에 우리가 할 수 있거나 해야 할 다른 작업이 있습니까?

감사해요!

업데이트:

여기에 my.cnf와 mysqltuner의 출력이 있습니다. 캐시 문제인 것 같습니다. 다시 한 번 감사드립니다!

# cat /etc/my.cnf
[client]
port            = ****
socket          = /var/lib/mysql/mysql.sock

[mysqld]
datadir=/mnt/persistent/mysql
port=****
socket=/var/lib/mysql/mysql.sock
key_buffer = 512M
max_allowed_packet = 64M
table_cache = 1024
sort_buffer_size = 8M
read_buffer_size = 4M
read_rnd_buffer_size = 2M
myisam_sort_buffer_size = 64M
thread_cache_size = 128M
tmp_table_size = 128M
join_buffer_size = 1M
query_cache_limit = 2M
query_cache_size= 64M
query_cache_type = 1
max_connections = 1000
thread_stack = 128K
thread_concurrency = 48
log-bin=mysql-bin
server-id       = 1
wait_timeout = 300
innodb_data_home_dir = /mnt/persistent/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 20G
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_thread_concurrency = 48
ft_min_word_len=3

[myisamchk]
ft_min_word_len=3
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

# ./mysqltuner.pl

 >>  MySQLTuner 1.2.0 - Major Hayden <[email protected]>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.52-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB +Federated +InnoDB -ISAM -NDBCluster 
[--] Data in MyISAM tables: 2G (Tables: 26)
[--] Data in InnoDB tables: 749M (Tables: 250)
[!!] Total fragmented tables: 262

-------- Security Recommendations  -------------------------------------------

-------- Performance Metrics -------------------------------------------------
[--] Up for: 31d 2h 30m 38s (680M q [253.371 qps], 2M conn, TX: 4825B, RX: 236B)
[--] Reads / Writes: 89% / 11%
[--] Total buffers: 20.6G global + 15.1M per thread (1000 max threads)
[OK] Maximum possible memory usage: 35.4G (51% of installed RAM)
[OK] Slow queries: 0% (35K/680M)
[OK] Highest usage of available connections: 53% (537/1000)
[OK] Key buffer size / total MyISAM indexes: 512.0M/457.2M
[OK] Key buffer hit rate: 100.0% (9B cached / 264K reads)
[OK] Query cache efficiency: 42.3% (260M cached / 615M selects)
[!!] Query cache prunes per day: 4384652
[OK] Sorts requiring temporary tables: 0% (1K temp sorts / 38M sorts)
[!!] Joins performed without indexes: 100404
[OK] Temporary tables created on disk: 17% (7M on disk / 45M total)
[OK] Thread cache hit rate: 99% (537 created / 2M connections)
[!!] Table cache hit rate: 0% (1K open / 946K opened)
[OK] Open file limit used: 9% (453/5K)
[OK] Table locks acquired immediately: 99% (758M immediate / 758M locks)
[OK] InnoDB data size / buffer pool: 749.3M/20.0G

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Enable the slow query log to troubleshoot bad queries
    Adjust your join queries to always utilize indexes
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    query_cache_size (> 64M)
    join_buffer_size (> 1.0M, or always use indexes with joins)
    table_cache (> 1024)

답변1

Would giving msyqld more memory help it cache queries and react faster?

MySQL에 더 많은 테이블 캐시를 제공하면 약간 도움이 될 수 있지만, 이것이 여러분 입장에서는 그리 큰 문제는 아니라고 생각합니다. MySQL 프로세스의 CPU 사용량이 매우 높기 때문에 이는 단순히 모든 연결로 인해 MySQL 속도가 느려지는 것이라고 생각합니다.

MySQL을 조정하는 데 사용하고 싶은 멋진 웹사이트 중 하나는 다음 MySQL 메모리 계산기입니다. http://www.omh.cc/mycnf/

또한 전체 MySQL 구성에 결함이 있는지 확인하므로 GitHub에서 아래 Perl 스크립트를 확인하는 것이 좋습니다. http://mysqltuner.com

마지막으로, 귀하의 경우에 도움이 될 것이라고 생각하는 것은 일부 HTTP 캐싱입니다. 귀하의 사이트가 매우 동적인 경우(데이터베이스 CPU 사용량 및 메모리가 상당히 높기 때문에) 일부 HTTP 캐싱을 사용하면 MySQL에서 약간의 부하가 걸릴 것입니다. 저는 개인적으로 Varnish를 사용하지만(지금은 하이퍼링크를 2개 이상 게시할 수 없으므로 간단한 Google 검색으로 표시할 수 있습니다), 다른 것들도 있습니다.

도움이 되었기를 바랍니다. 저는 여기에 있는 일부 사용자만큼 천재는 아니지만, 이 팁이 도움이 되기를 바랍니다.

답변2

Nginx를 사용하여 Apache를 전면에 내세울 수 있습니다. 이렇게 하면 클라이언트를 대신하여 Apache에 Nginx 프록시 요청이 이루어지며 압축을 Apache에도 오프로드할 수 있습니다. 이렇게 하면 서버 속도가 크롤링 속도로 느려지지 않는 수준으로 Max Apache 프로세스 수를 줄여 보십시오.

Apache 대신 정적 콘텐츠를 제공하도록 Nginx를 구성할 수도 있습니다.

이 링크는 시작하는 데 도움이 될 수 있습니다.

http://tumblr.intranation.com/post/766288369/using-nginx-reverse-proxy

관련 정보