Django / Apache / mod_wsgi 사이트에서 높은 CPU로드


10

Apache 벤치를 사용하여 AWS 소형 인스턴스 (Ubuntu 10.04)에서 django 1.21 / Apache / mod_wsgi 구성을로드 테스트하면 낮은 동시 요청에서 매우 높은 CPU로드 (업타임 및 vmstat 사용)가 표시됩니다.

ab -c 5 -n 1000 "my_url"

...이 가동 시간 출력을 유발합니다.

18:04:54 up 9 days, 16:54,  3 users,  load average: 5.33, 2.45, 1.91

Apache 벤치 동시성 값이 2 인 경우에도 CPU는 100 %입니다. 동일한 리전 / 영역의 다른 AWS 인스턴스에서 Apache 벤치를 실행하고 있습니다. 문제가 무엇인지, 어떻게 계속 디버깅해야하는지에 대한 아이디어가 있습니까?

세부:

  • 필사적으로 필자는 간단한 "Hello World"보기 (DB 호출 등)가없는 바닐라 장고 프로젝트 / 앱을 설치했습니다. 같은 결과입니다. 그래서 그것이 내 응용 프로그램 코드인지 의심합니다.
  • 로드 테스트 중에 메모리 사용량이 잘 보입니다.

다음은로드 테스트 전 / 중 / 후에 vmstat 출력입니다.

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
0  0      0 1034484  94848 321320    0    0     0     0   13   29  0  0 100  0
6  0      0 1032916  94848 321328    0    0     0     0  262  720  4 32 12  0
6  0      0 1031684  94848 321336    0    0     0     0  312  796  7 33  0  0
8  0      0 1030892  94856 321344    0    0     0    12  302  763  4 36  0  0
...
6  0      0 1030268  94864 321376    0    0     0     0  302  843  3 39  0  0
0  0      0 1032452  94868 321380    0    0     0    12  183  516  3 22 34  0
1  0      0 1033988  94868 321388    0    0     0     0   24   38  1  2 92  0
0  0      0 1033996  94868 321388    0    0     0     0   17   28  0  0 100  0
  • PHP를 사용하는 WordPress도 실행 중이므로 prefork 버전의 apache2를 실행하고 있습니다. (PHP는 Apache 작업자 버전에서 잘 작동하지 않습니다)

내 가상 호스트 파일은 다음과 같습니다.

WSGIPythonHome /home/xxx/webapps/ve/api
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName  app.xxx.mobi

        WSGIDaemonProcess snaplive user=www-data group=www-data processes=10 threads=1 maximum-requests=10000
        WSGIProcessGroup snaplive
        WSGIScriptAlias / /home/xxx/webapps/api/settings/apache/prod.wsgi
        DocumentRoot /home/xxx/webapps/api/static
        ErrorLog /var/log/apache2/django-live/error.log
        CustomLog /var/log/apache2/django-live/access.log combined
</VirtualHost>

내 httpd.conf 파일은 다음과 같습니다.

Alias /media /home/xxx/Django-1.2.1/django/contrib/admin/media
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so

StartServers 2
MinSpareServers 2
MaxSpareServers 5
MaxClients 50
MaxRequestsPerChild 3000
ServerLimit 8
Keepalive off
HostnameLookups Off

내 wsgi 파일은 다음과 같습니다.

import os
import sys
sys.stdout = sys.stderr

from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = WSGIHandler()

sys.path.append("/home/xxx/webapps/api")

로드 테스트 중에 브라우저에서 장고 URL을 쳐서 높은 CPU로드가 성능에 영향을 미치는 것을 정 성적으로 확인했습니다.

이것이 중요하지 않을 수도 있다는 것을 읽었지만 오류 로그 에이 내용이 많이 있습니다.

[Sun Sep 19 18:04:58 2010] [error] Exception KeyError: KeyError(-1218693376,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored

도움이 될 경우를 대비 한 Apache 벤치 결과는 다음과 같습니다.

Server Software:        Apache/2.2.14
Server Hostname:        app.xxx.mobi
Server Port:            80

Document Path:          /plist_catalog/test_data
Document Length:        0 bytes

Concurrency Level:      5
Time taken for tests:   27.720 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      269000 bytes
HTML transferred:       0 bytes
Requests per second:    36.08 [#/sec] (mean)
Time per request:       138.598 [ms] (mean)
Time per request:       27.720 [ms] (mean, across all concurrent requests)
Transfer rate:          9.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    2   8.5      1      88
Processing:     9  136 176.9     81    1182
Waiting:        9  135 176.6     81    1182
Total:         10  138 176.7     83    1183

Percentage of the requests served within a certain time (ms)
  50%     83
  66%     98
  75%    128
  80%    140
  90%    423
  95%    576
  98%    727
  99%    819
 100%   1183 (longest request)

답변:


2

문제는 apache2-mpm-prefork 대신 apache2-mpm-itk 패키지를 설치했다는 것입니다. apache2-mpm-itk는 apache2-mpm-prefork에서 파생되었지만 mod_wsgi와 함께 사용하면 성능이 떨어졌습니다.


ITK MPM 및 mod_wsgi를 사용하는 경우, 내장 프로세스에서 mod_wsgi 데몬 모드를 사용하고 Python 인터프리터 사용을 비활성화하는 것이 좋습니다. 내장 모드를 사용하는 경우 CGI와 마찬가지로 모든 요청에 ​​응용 프로그램을로드하는 것입니다.
Graham Dumpleton
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.