Commits

fan yu  committed 4958507

Add multi-processes supported (supervisor configure file).

  • Participants
  • Parent commits d63650f

Comments (0)

Files changed (4)

 import tornado.web
 
 import re
+import sys
 import base64
 from cStringIO import StringIO
 from tornado.httpclient import AsyncHTTPClient, HTTPRequest
     ])
 
 if __name__ == "__main__":
-    application.listen(40001)
+    if len(sys.argv)!=1 and sys.argv[1][:5] == '-port':
+        port = sys.argv[1].split('=')[1]
+    else:
+        port = config.PORT
+
+    application.listen(port)
     tornado.ioloop.IOLoop.instance().start()
 
 
 # coding:utf-8
 
+PORT = 40001
 BASE_URL = 'http://v0.api.upyun.com'
 
 

File misc/include/nginx.conf

 proxy_temp_path   /tmp/cache/proxy_temp_dir;
 
 #设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为30GB。
-proxy_cache_path  /tmp/cache/proxy_cache_dir levels=1:2 keys_zone=cache_pic:200m inactive=1d max_size=30g;
+proxy_cache_path  /tmp/cache/proxy_cache_dir levels=1:2 keys_zone=cache_pic:200m inactive=30d max_size=30g;
 
 upstream pic_cdn {
     server 127.0.0.1:40001 weight=1;
+    server 127.0.0.1:40002 weight=1;
+    server 127.0.0.1:40003 weight=1;
 }
 
 server {
     listen 80;
-    server_name p.42qu.me;
+    server_name x.42qu.me;
 
     location /
     {
         proxy_cache cache_pic;
         proxy_cache_key $host$uri$is_args$args;
-        #proxy_set_header Host $host;
-        #proxy_set_header X-Forwarded-For  $remote_addr;
+        proxy_set_header Host $host;
+        proxy_set_header X-Forwarded-For  $remote_addr;
         proxy_pass http://pic_cdn;
-        expires 1d;
+        expires max;
     }
 }
 

File misc/include/supervisord.conf

+
+[program:pic-cdn]
+
+command=python /home/fy/Project/pic-cdn/cdn.py -port=400%(process_num)02d
+process_name=%(program_name)s_%(process_num)02d
+directory=.
+autorestart=true
+redirect_stderr=true
+stdout_logfile=/var/log/supervisor/pic-cdn-%(process_num)02d.log
+stdout_logfile_maxbytes=1024MB
+stdout_logfile_backups=512
+stdout_capture_maxbytes=1MB
+stdout_events_enabled=false
+loglevel=warn
+numprocs_start=01
+numprocs=3
+