diff options
author | Zach Koopmans <zkoopmans@google.com> | 2020-07-29 10:03:57 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-07-29 10:06:38 -0700 |
commit | 6b4e11ab5074d41044e63337973ac2438ce2278e (patch) | |
tree | 0ecb8d935eb20afd56c4b0e02624aa1d9d381dcd /images/benchmarks/node/index.js | |
parent | a6b4538ae0b0020b14c8292d98e2549719a49e4c (diff) |
Port node benchmark.
PiperOrigin-RevId: 323810235
Diffstat (limited to 'images/benchmarks/node/index.js')
-rw-r--r-- | images/benchmarks/node/index.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/images/benchmarks/node/index.js b/images/benchmarks/node/index.js new file mode 100644 index 000000000..831015d18 --- /dev/null +++ b/images/benchmarks/node/index.js @@ -0,0 +1,42 @@ +const app = require('express')(); +const path = require('path'); +const redis = require('redis'); +const srs = require('secure-random-string'); + +// The hostname is the first argument. +const host_name = process.argv[2]; + +var client = redis.createClient({host: host_name, detect_buffers: true}); + +app.set('views', __dirname); +app.set('view engine', 'hbs'); + +app.get('/', (req, res) => { + var tmp = []; + /* Pull four random keys from the redis server. */ + for (i = 0; i < 4; i++) { + client.get(Math.floor(Math.random() * (100)), function(err, reply) { + tmp.push(reply.toString()); + }); + } + res.render('index', {text: tmp}); +}); + +/** + * Securely generate a random string. + * @param {number} len + * @return {string} + */ +function randomBody(len) { + return srs({alphanumeric: true, length: len}); +} + +/** Mutates one hundred keys randomly. */ +function generateText() { + for (i = 0; i < 100; i++) { + client.set(i, randomBody(1024)); + } +} + +generateText(); +app.listen(8080); |