我被安排项目进度,客户端就有一个网站,他是估计每天会收到1 2M击中了。 他58M的现有数据库的用户需要获取种子上逐个对注册新商标。 大多数网站的内容提供服务提供了从外部API数据与大部分数据存储在我们Mongo配置文件信息和保存安装程序完成API参数。
Nginx将端口80上和负载平衡到Node群集端口上8000 8010 。
我的问题是我们该怎么做缓存。 我来自LAMP背景所以我既用于编写静态HTML文件与PHP,服务那些最多减小MySQL负荷或使用Memcached这样,如果网站需要更高级别的缓存。 这种设置对我有点外国。
这是最理想至于最小响应时间和CPU加载?
1: 页面级缓存与Nginx
参考: http://andytson .com/blog/2010/04/page级别缓存与nginx/
server {
listen 80;
servername mysite.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
location / {
proxy_pass http://localhost:8080/;
proxy_cache anonymous;
}
# don't cache admin folder, send all requests through the proxy
location /admin {
proxy_pass http://localhost:8080/;
}
# handle static files directly. Set their expiry time to max, so they'll
# always use the browser cache after first request
location ~* (css|js|png|jpe?g|gif|ico)$ {
root /var/www/${host}/http;
expires max;
}
}
2: redis作为缓存桶
。 hash()
函数是 numbers()
函数在该页面上: http://jsperf .com/hashing字符串
function hash(str) {
var res = 0,
len = str.length;
for (var i = 0; i < len; i++) {
res = res * 31 + str.charCodeAt(i);
}
return res;
}
var apiUrl = 'https://www.myexternalapi.com/rest/someparam/someotherparam/?auth=3dfssd6s98d7f09s8df98sdef';
var key = hash(apiUrl).toString(); // 1.8006908172911553e+136
myRedisClient.set(key,theJSONresponse, function(err) {...});
3: 节点写入JSON文件
。 hash()
函数是 numbers()
函数在该页面上: http://jsperf .com/hashing字符串
function hash(str) {
var res = 0,
len = str.length;
for (var i = 0; i < len; i++) {
res = res * 31 + str.charCodeAt(i);
}
return res;
}
var fs = require('fs');
var apiUrl = 'https://www.myexternalapi.com/rest/someparam/someotherparam/?auth=3dfssd6s98d7f09s8df98sdef';
var key = hash(apiUrl).toString(); // 1.8006908172911553e+136
fs.writeFile('/var/www/_cache/' + key + '.json', theJSONresponse, function(err) {...});
4: varnish在前面
我做过研究,基准测试显示的那些一样。严禁身体的话我离开这个解决方案需要考虑,但我还是打开它进行了非常有意义: http://todsul .com/nginx varnish