Browse Source

Limit redis cache size of renderer by using a LRU cache

pull/6/head
Menci 6 years ago
parent
commit
0cb98135d8
  1. 3
      config-example.json
  2. 2
      libs/renderer.js
  3. 6
      libs/rendererd.js
  4. 1
      package.json
  5. 5
      yarn.lock

3
config-example.json

@ -126,5 +126,6 @@
"no_cdn": false,
"submissions_page_fast_pagination": false,
"username_regex": "^[a-zA-Z0-9\\-\\_]+$",
"site_for_download": ""
"site_for_download": "",
"renderer_cache_size": "30000"
}

2
libs/renderer.js

@ -1,6 +1,6 @@
const child_process = require('child_process');
const rendererd = child_process.fork(__dirname + '/rendererd', [syzoj.config.redis]);
const rendererd = child_process.fork(__dirname + '/rendererd', [syzoj.config.redis, parseInt(syzoj.config.renderer_cache_size)]);
const resolver = {};
let currentId = 0;

6
libs/rendererd.js

@ -19,11 +19,13 @@ const xss = new XSS.FilterXSS({
});
const Redis = require('redis');
const RedisLRU = require('redis-lru');
const util = require('util');
const redis = Redis.createClient(process.argv[2]);
const redisLru = RedisLRU(redis, parseInt(process.argv[3]));
const redisCache = {
get: util.promisify(redis.get).bind(redis),
set: util.promisify(redis.set).bind(redis)
get: redisLru.get.bind(redisLru),
set: redisLru.set.bind(redisLru)
};
async function highlight(code, lang) {

1
package.json

@ -59,6 +59,7 @@
"object-hash": "^1.3.1",
"randomstring": "^1.1.5",
"redis": "^2.8.0",
"redis-lru": "^0.6.0",
"reflect-metadata": "^0.1.13",
"request": "^2.74.0",
"request-promise": "^4.2.4",

5
yarn.lock

@ -2881,6 +2881,11 @@ redis-commands@^1.2.0:
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.4.0.tgz#52f9cf99153efcce56a8f86af986bd04e988602f"
integrity sha512-cu8EF+MtkwI4DLIT0x9P8qNTLFhQD4jLfxLR0cCNkeGzs87FN6879JOJwNQR/1zD7aSYNbU0hgsV9zGY71Itvw==
redis-lru@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/redis-lru/-/redis-lru-0.6.0.tgz#2a820a99011fe1a16a7ad2d67980def9d3336c7a"
integrity sha512-nDH+EHcUXp+cJdnkq8Hb+99kr82EDmAiFY40Bb02nB00A4N/dUqw3SCIJSgH8SUP2uee9EFijbMlf5WSul22uw==
redis-parser@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/redis-parser/-/redis-parser-2.6.0.tgz#52ed09dacac108f1a631c07e9b69941e7a19504b"

Loading…
Cancel
Save