nginx + gridfs + mongodb 大事记(残)

最近疯传一则 《MongoDB GridFS 数据读取效率 benchmark》的帖子,最初是在greader上看到的,当作一说,收藏之,也没太在意。咱老大却是很给力.."这个我们可以做".

额..好吧。对照着greader上的那则,google之,我勒个去,铺天盖地的转载、盗载...,就是没看到该是个什么样的配置法。得,自己动手 丰衣足食。

先去这个地方 http://github.com/mdirolf/nginx-gridfs看了下,n久没更新的patch,前段日子刚做完更新,而且还是针对 Mongo 的gridfs更新的(难道原始出处就是这丫折腾出来搭?)看在说明还很详尽的份上,用了!

(广告一则:不怎么用git,直接用的页面上给的download,下来发现mongo的drive包是空的,丫竟然另开了一个project,所以那个驱动得单下,记得要解包在drive目录下)

既然module是新的,那就用个新的nginx吧(0.8.52),还支持uwsgi,当然是后话了。

用的pymongo,似乎最近也更新了版本。不管了,总算是把图片折腾进去了,具体做法这儿 http://api.mongodb.org/python/1.9%2B/api/index.html可查。

g.put(open('/tmp/image/pe-logo-big.png','rb').read(),filename='hh.png')


nginx配置么:
location /image/ {
           gridfs static_file root_collection=images field=filename type=string;
           mongo 127.0.0.1:27017;
       }

浏览器试运行,不错,可以看到图,OK,下面按照帖子中的测试方式:
ab -n 50000 -c 10 http://192.168.2.131/image/hh.png

结果...
Server Software:        nginx/0.8.52
Server Hostname:        192.168.2.131
Server Port:            80

Document Path:          /image/hh.png
Document Length:        25338 bytes

Concurrency Level:      10
Time taken for tests:   628.173000 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      1274150000 bytes
HTML transferred:       1266900000 bytes
Requests per second:    79.60 [#/sec] (mean)
Time per request:       125.635 [ms] (mean)
Time per request:       12.563 [ms] (mean, across all concurrent requests)
Transfer rate:          1980.80 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   11  97.8      2    3055
Processing:     3  114 298.9     62    4001
Waiting:        0   79 242.9     30    3144
Total:          6  125 314.6     69    4004

Percentage of the requests served within a certain time (ms)
  50%     69
  66%    110
  75%    129
  80%    152
  90%    232
  95%    288
  98%    370
  99%   3016
 100%   4004 (longest request)


额,这个就有点杯具了,与帖子上的结果也差太多了吧。好吧,按照鲜花总要有绿叶衬托,
再试一下所谓的nginx直接读文件:
Server Software:        nginx/0.8.52
Server Hostname:        192.168.2.131
Server Port:            80

Document Path:          /pe-logo-big.png
Document Length:        25338 bytes

Concurrency Level:      10
Time taken for tests:   934.880000 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      1281150000 bytes
HTML transferred:       1266900000 bytes
Requests per second:    53.48 [#/sec] (mean)
Time per request:       186.976 [ms] (mean)
Time per request:       18.698 [ms] (mean, across all concurrent requests)
Transfer rate:          1338.27 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   18 165.1      3    3123
Processing:     3  168 500.1     69   10197
Waiting:        0   77 362.7     14    6119
Total:          5  186 525.6     74   10200

Percentage of the requests served within a certain time (ms)
  50%     74
  66%    111
  75%    130
  80%    159
  90%    263
  95%    296
  98%   3035
  99%   3097
 100%  10200 (longest request)

好吧在绿叶的衬托下,鲜花是有那么点吸引人之处了(虽然和那篇神帖结果截然相反了)。
不过也有可能在nginx时没有做缓存的缘故。
之所以在标题上加了个“残”,很显然,革命尚未成功啊。。后文待我喘过气再表!

你可能感兴趣的:(mongodb,nginx,python,Google,git)