버그를 제외하고 사이트가 느려지는 몇 가지 이유가 있습니다. 하나는 사용자 수, 사용자 활동, 데이터베이스 크기의 점진적인 증가이고, 다른 하나는 Discourse가 개발되면서 기능이 추가되고 소프트웨어 구성 요소가 업데이트됨에 따라 점점 더 커지는 것입니다.
하지만 응답성과 현재 머신이 적절한 사양인지에 관심을 기울이는 것이 가치가 있습니다.
(참고로, Hetzner의 가장 저렴한 머신은 이제 2GB RAM이었던 이전에 더 이상 구매할 수 없었던 가장 저렴한 머신과 동일한 가격에 4GB RAM을 제공합니다. 제 사이트 중 하나는 여전히 구형 2GB 사양으로 실행 중입니다.)
기록을 위해, 주요 사이트의 사용량을 추적해 왔으며, 최근에 마이그레이션이 이루어져 서버가 새로고침된 상태이므로 몇 가지 조사 결과를 포함하겠습니다. 데이터 양이 꽤 많습니다 - 굳이 자세히 보지 않으셔도 됩니다!
현재 머신의 상태는 다음과 같습니다.
# uptime
13:55:23 up 4 days, 21:10, 1 user, load average: 0.07, 0.08, 0.02
# free
total used free shared buff/cache available
Mem: 3905344 1638012 98492 481864 2168840 1595004
Swap: 4194288 252928 3941360
로그인 시 머신이 Memory usage: 45%라고 보고하는 것을 확인했습니다. 이는 ‘free’ 컬럼보다는 ‘used’ 컬럼과 가장 밀접하게 관련되어 있습니다.
저는 다음 명령어에서 주기적으로 읽기를 수행해 왔습니다.
date
uptime
free
ps aux|sort -n +5|tail
vmstat 5 5
그리고 제가 본 것은 ‘free’ 메모리가 프로세스의 RAM 사용량(RSS)이 증가하지 않는 상태에서 ‘buffer’ 및 ‘cache’ 메모리로 전환되고 있다는 것입니다. 이는 일부 호스팅 제공업체가 이를 쉽게 추적할 수 있게 해주더라도 ‘free’ 메모리를 추적하는 것이 좋지 않은 이유를 보여주는 것 같습니다. 또한 이 경우 메모리 누수가 없다는 것도 보여줍니다.
재부팅 직후에는 다음과 같은 모습을 보입니다:
# free
total used free shared buff/cache available
Mem: 3905344 1560508 996400 179712 1348436 1974692
Swap: 4194288 0 4194288
그리고 얼마 후
# ps aux|sort -n +5|tail
...
1000 1688 0.1 6.5 1006548 256428 ? Sl 16:44 0:10 unicorn master -E production -c config/unicorn.conf.rb
1000 2189 0.1 8.5 5657760 333248 ? Sl 16:45 0:06 unicorn worker[3] -E production -c config/unicorn.conf.rb
1000 2113 0.1 8.5 5656608 334352 ? Sl 16:45 0:07 unicorn worker[2] -E production -c config/unicorn.conf.rb
1000 2044 0.4 8.7 6052196 342380 ? Sl 16:44 0:23 unicorn worker[1] -E production -c config/unicorn.conf.rb
1000 2006 1.7 9.0 5628640 352492 ? Sl 16:44 1:33 unicorn worker[0] -E production -c config/unicorn.conf.rb
1000 1971 3.1 11.1 6033652 435388 ? SNl 16:44 2:54 sidekiq 6.5.12 discourse [0 of 5 busy]
# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
...
0 0 0 866112 314288 1083816 0 0 32 28 484 621 4 1 95 0 0
sidekiq(435 MByte)과 unicorn(각각 330-350)가 가장 큰 프로세스임을 알 수 있습니다.
시간이 지남에 따라 free RAM과 그 다음 sidekiq RAM(RSS) 사용량이 감소합니다. 이는 페이지 아웃(paged out) 때문으로 추정되며, 과도한 영향은 없습니다 - 머신은 페이지ング 활동을 보이지 않습니다. 대신 버퍼 및 캐시 공간이 증가하는 것으로 보입니다.
# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
...
0 0 0 679764 326988 1190840 0 0 0 11 285 396 1 1 98 0 0
약 14시간 후:
# uptime
10:12:06 up 17:27, 1 user, load average: 0.04, 0.02, 0.00
# ps aux|sort -n +5|tail
...
1000 2006 1.2 9.6 5647908 377424 ? Sl Sep05 12:42 unicorn worker[0] -E production -c config/unicorn.conf.rb
1000 1971 1.8 11.3 6431988 444184 ? SNl Sep05 18:51 sidekiq 6.5.12 discourse [0 of 5 busy]
# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
...
0 0 2048 199972 342480 1576156 0 0 0 17 361 511 2 2 96 0 0
나중에…
# uptime
19:52:00 up 1 day, 3:07, 1 user, load average: 0.02, 0.06, 0.01
# ps aux|sort -n +5|tail
...
1000 2006 1.2 9.8 5654308 382944 ? Sl Sep05 20:44 unicorn worker[0] -E production -c config/unicorn.conf.rb
1000 1971 1.5 11.1 6431668 436340 ? SNl Sep05 25:04 sidekiq 6.5.12 discourse [0 of 5 busy]
# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
...
0 0 2304 103356 301632 1690136 0 0 0 10 360 511 1 1 98 0 0
나중에…
# uptime
12:13:09 up 1 day, 19:28, 2 users, load average: 0.05, 0.06, 0.01
# ps aux|sort -n +5|tail
...
1000 2006 1.2 9.1 5654820 358612 ? Sl Sep05 31:47 unicorn worker[0] -E production -c config/unicorn.conf.rb
1000 1971 1.3 10.0 6431668 393584 ? SNl Sep05 35:08 sidekiq 6.5.12 discourse [0 of 5 busy]
# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
...
0 0 284416 281596 77904 1908528 0 0 0 38 315 450 1 1 98 0 0
나중에
# uptime
13:26:42 up 2 days, 20:42, 1 user, load average: 0.20, 0.06, 0.02
# ps aux|sort -n +5|tail
...
1000 2006 1.2 9.3 5789072 365720 ? Sl Sep05 51:54 unicorn worker[0] -E production -c config/unicorn.conf.rb
1000 1971 1.2 10.0 6433332 393472 ? SNl Sep05 50:44 sidekiq 6.5.12 discourse [0 of 5 busy]
# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
...
0 0 242944 82016 95188 2082180 0 0 0 131 332 488 1 1 98 0 0
나중에
# uptime
09:21:33 up 3 days, 16:36, 1 user, load average: 0.13, 0.10, 0.03
# free
total used free shared buff/cache available
Mem: 3905344 1618936 323032 476664 1963376 1619208
Swap: 4194288 250112 3944176
# ps aux|sort -n +5|tail
...
1000 2006 1.2 9.3 5789200 363572 ? Sl Sep05 67:02 unicorn worker[0] -E production -c config/unicorn.conf.rb
1000 1971 1.1 9.6 6433652 377472 ? SNl Sep05 63:14 sidekiq 6.5.12 discourse [0 of 5 busy]
# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
...
0 0 250112 321888 56052 1906672 0 0 2 13 293 420 1 0 99 0 0
나중에
# uptime
13:55:23 up 4 days, 21:10, 1 user, load average: 0.07, 0.08, 0.02
# free
total used free shared buff/cache available
Mem: 3905344 1638012 98492 481864 2168840 1595004
Swap: 4194288 252928 3941360
# ps aux|sort -n +5|tail
...
1000 1971 1.1 9.5 6434676 371648 ? SNl Sep05 80:49 sidekiq 6.5.12 discourse [0 of 5 busy]
1000 2006 1.2 9.5 5658468 373404 ? Sl Sep05 88:44 unicorn worker[0] -E production -c config/unicorn.conf.rb
# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
...
1 0 252928 101040 86736 2082372 0 0 0 10 333 482 1 0 99 0 0