Skip to content

Commit dbc46e4

Browse files
committed
add benchmarking
1 parent f6d65ea commit dbc46e4

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
**/node_modules
2+
**/start-time.txt

3-recommended/Tiltfile

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,30 @@
22

33
k8s_yaml('kubernetes.yaml')
44
k8s_resource('example-nodejs', port_forwards=8000,
5-
#resource_deps=['deploy']
6-
)
5+
resource_deps=['deploy']
6+
)
77

88
# Records the current time, then kicks off a server update.
99
# Normally, you would let Tilt do deploys automatically, but this
1010
# shows you how to set up a custom workflow that measures it.
11-
# local_resource(
12-
# 'deploy',
13-
# 'date +%s%N > start-time.txt',
14-
# )
11+
local_resource(
12+
'deploy',
13+
'date +%s%N > start-time.txt',
14+
)
1515

1616
# Add a live_update rule to our docker_build
17-
# congrats = "🎉 Congrats, you ran a live_update! 🎉"
17+
congrats = "🎉 Congrats, you ran a live_update! 🎉"
1818
docker_build('example-nodejs-image', '.',
1919
live_update=[
2020
sync('.', '/app'),
21-
sync('./package.json', '/app/package.json'),
22-
sync('./yarn.lock', '/app/yarn.lock'),
2321
run('cd /app && yarn install', trigger=['./package.json', './yarn.lock']),
2422

2523
# if all that changed was start-time.txt, make sure the server
2624
# reloads so that it will reflect the new startup time
27-
# run('touch /app/app.py', trigger='./start-time.txt'),
25+
run('touch /app/index.js', trigger='./start-time.txt'),
2826

2927
# add a congrats message!
30-
# run('sed -i "s/Hello cats!/{}/g" /app/templates/index.html'.
31-
# format(congrats)),
28+
run('sed -i "s/Hello cats!/{}/g" /app/views/index.mustache'.
29+
format(congrats)),
3230
])
3331

3-recommended/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
/*
22
Gratefully adapted from https://github.com/HemingwayLee/sample-mustache-express
33
*/
4+
const fs = require('fs');
5+
46
const express = require('express');
57
const app = express();
68
const mustacheExpress = require('mustache-express');
79

10+
let timeSince = 'N/A';
11+
812
app.engine('mustache', mustacheExpress());
913

1014
app.set('view engine', 'mustache');
1115
app.set('views', __dirname + '/views');
12-
app.use(express.static('public'))
16+
app.use(express.static('public'));
1317

1418
app.get('/', function(req, res) {
15-
const data = {
16-
time: 'a million years'
17-
};
18-
19-
res.render('index.mustache', data);
19+
res.render('index.mustache', {
20+
time: timeSince,
21+
});
2022
});
2123

2224
app.listen(8000, () => {
25+
timeSince = getSecsElapsedSinceDeploy();
2326
console.log('Server running at http://localhost:8000/');
2427
});
28+
29+
function getSecsElapsedSinceDeploy() {
30+
let curTimeMs = new Date().getTime();
31+
let contents = fs.readFileSync('/app/start-time.txt', 'utf8');
32+
let startTimeMs = parseInt(contents.trim()) / 10**6;
33+
return ((curTimeMs - startTimeMs) / 10**3).toFixed(2)
34+
}

0 commit comments

Comments
 (0)