github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/images/benchmarks/node/index.js (about) 1 const app = require('express')(); 2 const path = require('path'); 3 const redis = require('redis'); 4 const srs = require('secure-random-string'); 5 6 // The hostname is the first argument. 7 const host_name = process.argv[2]; 8 9 var client = redis.createClient({host: host_name, detect_buffers: true}); 10 11 app.set('views', __dirname); 12 app.set('view engine', 'hbs'); 13 14 app.get('/', (req, res) => { 15 var tmp = []; 16 /* Pull four random keys from the redis server. */ 17 for (i = 0; i < 4; i++) { 18 client.get(Math.floor(Math.random() * (100)), function(err, reply) { 19 tmp.push(reply.toString()); 20 }); 21 } 22 res.render('index', {text: tmp}); 23 }); 24 25 /** 26 * Securely generate a random string. 27 * @param {number} len 28 * @return {string} 29 */ 30 function randomBody(len) { 31 return srs({alphanumeric: true, length: len}); 32 } 33 34 /** Mutates one hundred keys randomly. */ 35 function generateText() { 36 for (i = 0; i < 100; i++) { 37 client.set(i, randomBody(1024)); 38 } 39 } 40 41 generateText(); 42 app.listen(8080);