Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update simple-profiling.md #1975

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions locale/en/docs/guides/simple-profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved
our system:

```javascript

const express = require('express', '4.16.4' )
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved
const crypto = require('crypto')
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved
const app = express()
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved
const port = 3000
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved
const users = {}
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved

app.get('/newUser', (req, res) => {
let username = req.query.username || '';
const password = req.query.password || '';
Expand All @@ -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 || '';
Expand All @@ -72,6 +77,8 @@ app.get('/auth', (req, res) => {
res.sendStatus(401);
}
});

app.listen(port, () => console.log(`profiling example app running on port ${port}`))
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved
```

*Please note that these are NOT recommended handlers for authenticating users in
Expand All @@ -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"
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved
```

and put some load on the server using `ab` (ApacheBench):

```
ab -k -c 20 -n 250 "http://localhost:8080/auth?username=matt&password=password"
kcacciatore marked this conversation as resolved.
Show resolved Hide resolved
```

Expand Down Expand Up @@ -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 {
Expand Down