Varnish ã CouchDB ç¨ã®Reverse Proxyã«æ´»ç¨ããã
ãç¡æ²æ±°ãã¦ããã¾ããçãã¦ãã¾ãã
ãã¦ãCouchDB 1.0 ãã§ã¦ãincremental replication ãã ãã¶å®å®ããæãããã®ã§ãèªå® ã® CouchDB ã§ãã¼ããã©ã³ã¹ããããªãã¾ããã
Apache mod_proxy_balancer ã¨ããæãããã®ã§ãããIncremental (MapReduce + Replication) ã¨ããç°å¢ã§ã¯ãHigh Performance 㪠Caching Proxy ã«ãªã Varnish ã¨ããé¸æè¢ããããããããªã®ã§è©¦ãã¦ãã¾ãã
æ§æ
- CPU: Opteron Dual Core 1.8 GHz
- Memory: 8GB
- Servers: http://relax:5984/, slave: http://relax:15984/ (master 㨠slave ã¯åããµã¼ãã¼ä¸ããã ãããã£ã¹ã¯ã¯å¥)
㧠twitter ã®ã¿ã¤ã ã©ã¤ã³ãããã¯ã¢ãããã¦ãã http://www.yssk22.info/relax/_design/mytweets/_list/timeline/by_date?descending=true ã®ãã¼ã¿ã対象ã«ãã¾ãã1ã¤ã®ããã¥ã¡ã³ã㯠1.5KB ãããã§ãã
CouchDB ã®è¨å®
init.d ã®èµ·åã¹ã¯ãªããã« Incremental Replication ãä»è¾¼ãã§ããã¾ããããå¿ããã¨ããã£ããåèµ·åããã¨ãã«ã¬ããªã±ã¼ã·ã§ã³ãæ¢ã¾ã£ã¦ãããã¨ãããããæãã«ãªãã®ã§æ³¨æã
#!/bin/sh /opt/relax/master/couchdb/pro-1.0.0/etc/init.d/couchdb $@ /opt/relax/slave/couchdb/pro-1.0.0/etc/init.d/couchdb $@ start_replication () { sleep 1 # wait for slave waking up curl -X POST --data '{"source": "http://127.0.0.1:5984/relax", "target": "http://127.0.0.1:15984/relax", "continuous" : true }' http://localhost:5984/_replicate } case "$1" in start) start_replication ;; restart) start_replication ;; *) ;; esac
Varnish ã®è¨å®
åå¿è
ãªã®ã§ã vcl ã«ãããªæã㧠ã¨ãããã GETã¨HEAD ããã¼ããã©ã³ã¹ãã¦ãããã°ããããã¨ã
ã¾ãã¯ãå¹æ測å®ã®ããã«ãVarnish ãã£ãã·ã¥ãç¡å¹ã«ãã¦ããã¾ããã
backend default { .host = "127.0.0.1"; .port = "5984"; } backend slave { .host = "127.0.0.1"; .port = "15984"; } director couchdb round-robin { { .backend = default; } { .backend = slave; } } sub vcl_recv { if (req.request != "GET" && req.request != "HEAD") { return (pass); } set req.backend = couchdb; return (pass); }
ab ãã¦ã¿ã
ã¯ã©ã¤ã¢ã³ãã«ã¯ iMac (Core2Duo 3.02GHz, 4GB Memory) ã使ãã¾ãã
ã¾ãã¯ãç´æ¥CouchDBã«ãã 1 tweet ãç´æ¥ãããæãã§ã
$ ab -n 1000 -c 30 "http://relax:5984/relax/fffdcaf2b6bafa2f6a39a513d48d5e45" Concurrency Level: 30 Time taken for tests: 2.431 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 1687000 bytes HTML transferred: 1452000 bytes Requests per second: 411.42 [#/sec] (mean) Time per request: 72.918 [ms] (mean) Time per request: 2.431 [ms] (mean, across all concurrent requests) Transfer rate: 677.80 [Kbytes/sec] received
- c 30 ãæ£ãããã¯ã¨ããã(ããã¡ãã£ã¨å¤ãã¦ãããããª...)ããããªæãã§ãã
Varnish çµç±ã§ãããã¦ã¿ã¾ãã
$ ab -n 1000 -c 30 "http://relax:6081/relax/fffdcaf2b6bafa2f6a39a513d48d5e45" Concurrency Level: 30 Time taken for tests: 1.671 seconds Complete requests: 1000 Failed requests: 7 (Connect: 0, Receive: 0, Length: 7, Exceptions: 0) Write errors: 0 Non-2xx responses: 7 Total transferred: 1747622 bytes HTML transferred: 1445098 bytes Requests per second: 598.52 [#/sec] (mean) Time per request: 50.123 [ms] (mean) Time per request: 1.671 [ms] (mean, across all concurrent requests) Transfer rate: 1021.48 [Kbytes/sec] received
ã¡ãã£ã¨å¹æãã§ãããã§ããbeam.smp èªä½ã¯ concurrent ã«åãã¦ã¯ãããã§ããã©ããããããªä½ç¨ã®ããã§(ã¡ãã£ã¨è©³ããè¦ãå¿ è¦ãããã)ãåä½æã 500 rec/sec, RBæã 600 rec/sec ãããã«ãªã£ã¦ãã¾ããã
ab ãã¦ã¿ã (2)
次㫠MapReduce Viewãããã¯æ´æ°ããªããã¯ãããªãã¨ä½ãæå³ããªãã®ã§ãããã¨ãããããtweetãæ¥ä»é ã«ä¸¦ã³æ¿ãã¦ã10件ã¨ãURIããããã¾ããã¾ãã
CouchDB ç´æ¥ã
$ ab -n 1000 -c 30 "http://relax:5984/relax/_design/mytweets/_view/by_date?limit=10&descending=true" Concurrency Level: 30 Time taken for tests: 13.289 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 27286000 bytes HTML transferred: 27082000 bytes Requests per second: 75.25 [#/sec] (mean) Time per request: 398.667 [ms] (mean) Time per request: 13.289 [ms] (mean, across all concurrent requests) Transfer rate: 2005.17 [Kbytes/sec] received
Varnish çµç±ã
$ ab -n 1000 -c 30 "http://relax:6081/relax/_design/mytweets/_view/by_date?limit=10&descending=true" Concurrency Level: 30 Time taken for tests: 10.043 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 27377000 bytes HTML transferred: 27082000 bytes Requests per second: 99.57 [#/sec] (mean) Time per request: 301.293 [ms] (mean) Time per request: 10.043 [ms] (mean, across all concurrent requests) Transfer rate: 2662.06 [Kbytes/sec] received
ãã¡ããè¥å¹²æ¹åãããæããå ¨é¨ã¡ã¢ãªã«ã®ã£ã¡ããã®ã§ãããªå¤ãããªãããªã¼ãã¨æãããã
ab ãã¦ã¿ã (3)
æå¾ã«ãHTMLã¬ã³ããªã³ã°ã®URIããã£ã¦ã¿ã¾ããããã¯æ¯åJSããã»ã¹ãCGIçã«åãã®ã§ãã©ãã§ãããã
$ ab -n 1000 -c 30 "http://relax:5984/relax/_design/mytweets/_list/timeline/by_date?limit=10&descending=true" Concurrency Level: 30 Time taken for tests: 40.317 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 7127000 bytes HTML transferred: 6942000 bytes Requests per second: 24.80 [#/sec] (mean) Time per request: 1209.498 [ms] (mean)
å²ã¨ããã°ã£ã¦ããæ°ããã¾ããJSã§HTMLãã¬ã³ããªã³ã°ããã£ã¦çµæ§éãå¦çãªã®ã§ããã(pure JSå®è£ ã®template engineãããªããã®ã§ããã
Varnishçã
$ ab -n 1000 -c 30 "http://relax:6081/relax/_design/mytweets/_list/timeline/by_date?Concurrency Level: 30 Time taken for tests: 34.386 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 7217500 bytes HTML transferred: 6942000 bytes Requests per second: 29.08 [#/sec] (mean) Time per request: 1031.594 [ms] (mean) Time per request: 34.386 [ms] (mean, across all concurrent requests) Transfer rate: 204.97 [Kbytes/sec] received
ããã¾ãããããªããªã£ã¡ããã¾ããã
ããããVarnish Cache ãæå¹ã«ãã¦ã¿ãããã
vcl_recv ã§æå¾ã« lookup ãã¾ããå°ããã£ãã·ã¥ã¯ããã©ã«ãã®1GBã
sub vcl_recv { if (req.request != "GET" && req.request != "HEAD") { return (pass); } set req.backend = couchdb; return (lookup); }
測å®
$ ab -n 1000 -c 30 "http://relax:6081/relax/_design/mytweets/_list/timeline/by_date?descending=true" Concurrency Level: 30 Time taken for tests: 1.673 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 196220832 bytes HTML transferred: 195932256 bytes Requests per second: 597.55 [#/sec] (mean) Time per request: 50.205 [ms] (mean) Time per request: 1.673 [ms] (mean, across all concurrent requests) Transfer rate: 114504.36 [Kbytes/sec] received
20åãããé«éã«ãªãã¾ããã tweet èªä½ã¯ cron 㧠10 åãã¨ã«ã¾ã¨ãã¦ã¨ã£ã¦ãã¦CouchDBã«ã¤ã£ããã§ããã®ã§ããã®ã¿ã¤ãã³ã°ã§ Varnish Cache ãç ´æ£ããããããã CouchDB ã® update notirifcation ã使ã£ã¦ Cache ãç ´æ£ããããããã
ãªãããã®çµã¿åããã¯ãã°ãããæ°ãããã
ããå°ãæ°ã«ãªããã¨ã
master -> slave æ§æã§ãããéåãã®incremental replicationãèµ·åæã«ä»è¾¼ãã§ããã°ãPOST, PUT ãVarnishã«ãããããã¨ãã§ããããããªããã¨ã