Share one redis-mpool across the application

This commit is contained in:
Raul Ochoa 2014-09-24 11:42:36 +02:00
parent 9d36ae293c
commit 24cbd192aa
5 changed files with 25 additions and 14 deletions

View File

@ -2,6 +2,7 @@
--------------------
Enhancements:
- Share one redis-mpool across the application
- Upgrades windshaft and cartodb-redis
- Supports `!scale_denominator!` dynamic param in SQL queries
- Metrics revamp: removes and adds some metrics

15
app.js
View File

@ -8,7 +8,8 @@
*/
var path = require('path'),
fs = require('fs')
fs = require('fs'),
RedisPool = require('redis-mpool')
;
@ -31,7 +32,7 @@ var _ = require('underscore');
global.environment = require(__dirname + '/config/environments/' + ENV);
global.environment.api_hostname = require('os').hostname().split('.')[0];
global.log4js = require('log4js')
global.log4js = require('log4js');
log4js_config = {
appenders: [],
replaceConsole:true
@ -65,10 +66,16 @@ if ( global.environment.rollbar ) {
log4js.configure(log4js_config, { cwd: __dirname });
global.logger = log4js.getLogger();
var redisOpts = _.extend(global.environment.redis, {
name: 'windshaft_cartodb',
reportInterval: 5000
}),
redisPool = new RedisPool(redisOpts);
// Include cartodb_windshaft only _after_ the "global" variable is set
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/28
var CartodbWindshaft = require('./lib/cartodb/cartodb_windshaft');
var serverOptions = require('./lib/cartodb/server_options')();
var CartodbWindshaft = require('./lib/cartodb/cartodb_windshaft'),
serverOptions = require('./lib/cartodb/server_options')(redisPool);
ws = CartodbWindshaft(serverOptions);

View File

@ -1,10 +1,6 @@
var _ = require('underscore')
, Step = require('step')
, Windshaft = require('windshaft')
, redisPool = require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:cartodb'}))
// TODO: instanciate cartoData with redisPool
, cartoData = require('cartodb-redis')(global.environment.redis)
, SignedMaps = require('./signed_maps.js')
, TemplateMaps = require('./template_maps.js')
, Cache = require('./cache_validator')
@ -26,6 +22,11 @@ var CartodbWindshaft = function(serverOptions) {
}
}
var redisPool = serverOptions.redis.pool
|| require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:cartodb'}));
var cartoData = require('cartodb-redis')({pool: redisPool});
if(serverOptions.cache_enabled) {
console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', serverOptions.varnish_port);
Cache.init(serverOptions.varnish_host, serverOptions.varnish_port, serverOptions.varnish_secret);

View File

@ -1,6 +1,5 @@
var _ = require('underscore')
, Step = require('step')
, cartoData = require('cartodb-redis')(global.environment.redis)
, Cache = require('./cache_validator')
, QueryTablesApi = require('./api/query_tables_api')
, crypto = require('crypto')
@ -16,11 +15,11 @@ if ( _.isUndefined(global.environment.sqlapi.domain) ) {
}
}
module.exports = function(){
module.exports = function(redisPool) {
var lzmaWorker = new LZMA();
var queryTablesApi = new QueryTablesApi();
var cartoData = require('cartodb-redis')({pool: redisPool}),
lzmaWorker = new LZMA(),
queryTablesApi = new QueryTablesApi();
var rendererConfig = _.defaults(global.environment.renderer || {}, {
cache_ttl: 60000, // milliseconds
@ -77,6 +76,9 @@ module.exports = function(){
// See http://github.com/CartoDB/Windshaft-cartodb/issues/161
me.redis.unwatchOnRelease = false;
// Re-use redisPool
me.redis.pool = redisPool;
/* This whole block is about generating X-Cache-Channel { */
// TODO: review lifetime of elements of this cache

View File

@ -29,7 +29,7 @@
"request": "~2.9.203",
"cartodb-redis": "https://github.com/CartoDB/node-cartodb-redis/tarball/0.11.0",
"cartodb-psql": "https://github.com/CartoDB/node-cartodb-psql/tarball/0.4.0",
"redis-mpool": "https://github.com/CartoDB/node-redis-mpool/tarball/0.1.0",
"redis-mpool": "https://github.com/CartoDB/node-redis-mpool/tarball/master",
"lzma": "~1.3.7",
"log4js": "~0.6.17",
"rollbar": "~0.3.13"