From cbef6d8072843b890cb8a686106f7dc18a5f2368 Mon Sep 17 00:00:00 2001 From: Kyle Cacciatore Date: Thu, 3 Jan 2019 13:48:40 -0500 Subject: [PATCH 1/6] Update simple-profiling.md Identified a missing parameter in the performance update (I was using v11.2.0). Also updated code sample that is runnable from copy/paste, and added link to installing Express. --- locale/en/docs/guides/simple-profiling.md | 24 +++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/locale/en/docs/guides/simple-profiling.md b/locale/en/docs/guides/simple-profiling.md index a980721f9dfa3..bea6367aa07d1 100644 --- a/locale/en/docs/guides/simple-profiling.md +++ b/locale/en/docs/guides/simple-profiling.md @@ -27,10 +27,17 @@ Let's see how the built-in profiler can help provide insight into application performance. To illustrate the use of the tick profiler, we will work with a simple Express -application. Our application will have two handlers, one for adding new users to +application (See [here](http://expressjs.com/en/starter/installing.html) for installation instructions). Our application will have two handlers, one for adding new users to our system: ```javascript + +const express = require('express', '4.16.4' ) +const crypto = require('crypto') +const app = express() +const port = 3000 +const users = {} + app.get('/newUser', (req, res) => { let username = req.query.username || ''; const password = req.query.password || ''; @@ -48,11 +55,9 @@ app.get('/newUser', (req, res) => { res.sendStatus(200); }); -``` -and another for validating user authentication attempts: +// and another for validating user authentication attempts: -```javascript app.get('/auth', (req, res) => { let username = req.query.username || ''; const password = req.query.password || ''; @@ -72,6 +77,8 @@ app.get('/auth', (req, res) => { res.sendStatus(401); } }); + +app.listen(port, () => console.log(`profiling example app running on port ${port}`)) ``` *Please note that these are NOT recommended handlers for authenticating users in @@ -86,10 +93,15 @@ high latency on requests. We can easily run the app with the built in profiler: NODE_ENV=production node --prof app.js ``` -and put some load on the server using `ab` (ApacheBench): +We'll create a new user: ``` curl -X GET "http://localhost:8080/newUser?username=matt&password=password" +``` + +and put some load on the server using `ab` (ApacheBench): + +``` ab -k -c 20 -n 250 "http://localhost:8080/auth?username=matt&password=password" ``` @@ -228,7 +240,7 @@ app.get('/auth', (req, res) => { return res.sendStatus(400); } - crypto.pbkdf2(password, users[username].salt, 10000, 512, (err, hash) => { + crypto.pbkdf2(password, users[username].salt, 10000, 512, 'sha512', (err, hash) => { if (users[username].hash.toString() === hash.toString()) { res.sendStatus(200); } else { From ab1df2e1c0656f3e9f9c782ef8dd71ae5d66bcda Mon Sep 17 00:00:00 2001 From: Kyle Cacciatore Date: Thu, 3 Jan 2019 14:44:04 -0500 Subject: [PATCH 2/6] Updated simple-profiling.md styling Updated based on styling guidelines. --- locale/en/docs/guides/simple-profiling.md | 29 +++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/locale/en/docs/guides/simple-profiling.md b/locale/en/docs/guides/simple-profiling.md index bea6367aa07d1..fab57930084c2 100644 --- a/locale/en/docs/guides/simple-profiling.md +++ b/locale/en/docs/guides/simple-profiling.md @@ -32,11 +32,11 @@ our system: ```javascript -const express = require('express', '4.16.4' ) -const crypto = require('crypto') -const app = express() -const port = 3000 -const users = {} +const express = require('express', '4.16.4' ); +const crypto = require('crypto'); +const app = express(); +const port = 3000; +const users = {}; app.get('/newUser', (req, res) => { let username = req.query.username || ''; @@ -78,7 +78,9 @@ app.get('/auth', (req, res) => { } }); -app.listen(port, () => console.log(`profiling example app running on port ${port}`)) +app.listen(port, () => { + console.log(`example app running on port ${port}`) +}); ``` *Please note that these are NOT recommended handlers for authenticating users in @@ -240,13 +242,14 @@ app.get('/auth', (req, res) => { return res.sendStatus(400); } - crypto.pbkdf2(password, users[username].salt, 10000, 512, 'sha512', (err, hash) => { - if (users[username].hash.toString() === hash.toString()) { - res.sendStatus(200); - } else { - res.sendStatus(401); - } - }); + crypto.pbkdf2(password, users[username].salt, 10000, 512, 'sha512', + (err, hash) => { + if (users[username].hash.toString() == hash.toString()) { + res.sendStatus(200); + } else { + res.sendStatus(401); + } + }); }); ``` From 2966b48c9bf9cd5889f714ef1e69f78a4b72802a Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 3 Jan 2019 15:07:06 -0500 Subject: [PATCH 3/6] Update locale/en/docs/guides/simple-profiling.md Accepted suggested change in line length Co-Authored-By: kcacciatore --- locale/en/docs/guides/simple-profiling.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/locale/en/docs/guides/simple-profiling.md b/locale/en/docs/guides/simple-profiling.md index fab57930084c2..758412fd6963a 100644 --- a/locale/en/docs/guides/simple-profiling.md +++ b/locale/en/docs/guides/simple-profiling.md @@ -27,7 +27,9 @@ Let's see how the built-in profiler can help provide insight into application performance. To illustrate the use of the tick profiler, we will work with a simple Express -application (See [here](http://expressjs.com/en/starter/installing.html) for installation instructions). Our application will have two handlers, one for adding new users to +application (See [here](http://expressjs.com/en/starter/installing.html) for +installation instructions). Our application will have two handlers, one for +adding new users to our system: ```javascript From a733cb4397ea4c9eca4d8ba1f9d0503a1ba385e9 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 3 Jan 2019 15:08:36 -0500 Subject: [PATCH 4/6] Update locale/en/docs/guides/simple-profiling.md indentation fix Co-Authored-By: kcacciatore --- locale/en/docs/guides/simple-profiling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/en/docs/guides/simple-profiling.md b/locale/en/docs/guides/simple-profiling.md index 758412fd6963a..c306ef8af7ceb 100644 --- a/locale/en/docs/guides/simple-profiling.md +++ b/locale/en/docs/guides/simple-profiling.md @@ -81,7 +81,7 @@ app.get('/auth', (req, res) => { }); app.listen(port, () => { - console.log(`example app running on port ${port}`) + console.log(`example app running on port ${port}`); }); ``` From 1bf19c1feacdff3143545e161fa791b4f26a8c14 Mon Sep 17 00:00:00 2001 From: Kyle Cacciatore Date: Thu, 3 Jan 2019 15:48:34 -0500 Subject: [PATCH 5/6] Removed versioning Removed explicit versioning of Express --- locale/en/docs/guides/simple-profiling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/en/docs/guides/simple-profiling.md b/locale/en/docs/guides/simple-profiling.md index c306ef8af7ceb..937074d782b1c 100644 --- a/locale/en/docs/guides/simple-profiling.md +++ b/locale/en/docs/guides/simple-profiling.md @@ -34,7 +34,7 @@ our system: ```javascript -const express = require('express', '4.16.4' ); +const express = require('express'); const crypto = require('crypto'); const app = express(); const port = 3000; From 4e000950d51837d2f9e4950259ee6d7534189da5 Mon Sep 17 00:00:00 2001 From: Kyle Cacciatore Date: Fri, 4 Jan 2019 08:29:49 -0500 Subject: [PATCH 6/6] Changed Port Realized the port number in the code sample was inconsistent with the curl/ab instructions --- locale/en/docs/guides/simple-profiling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/en/docs/guides/simple-profiling.md b/locale/en/docs/guides/simple-profiling.md index 937074d782b1c..7b4178ad01492 100644 --- a/locale/en/docs/guides/simple-profiling.md +++ b/locale/en/docs/guides/simple-profiling.md @@ -37,7 +37,7 @@ our system: const express = require('express'); const crypto = require('crypto'); const app = express(); -const port = 3000; +const port = 8080; const users = {}; app.get('/newUser', (req, res) => {