Skip to content
Closed
Changes from 2 commits
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
39 changes: 27 additions & 12 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
Comment thread
kcacciatore marked this conversation as resolved.
Outdated
our system:

```javascript

const express = require('express', '4.16.4' );
Comment thread
kcacciatore marked this conversation as resolved.
Outdated
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 || '';
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,10 @@ app.get('/auth', (req, res) => {
res.sendStatus(401);
}
});

app.listen(port, () => {
console.log(`example app running on port ${port}`)
Comment thread
kcacciatore marked this conversation as resolved.
Outdated
});
```

*Please note that these are NOT recommended handlers for authenticating users in
Expand All @@ -86,10 +95,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"
Comment thread
kcacciatore marked this conversation as 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"
Comment thread
kcacciatore marked this conversation as resolved.
```

Expand Down Expand Up @@ -228,13 +242,14 @@ app.get('/auth', (req, res) => {
return res.sendStatus(400);
}

crypto.pbkdf2(password, users[username].salt, 10000, 512, (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',
Comment thread
kcacciatore marked this conversation as resolved.
(err, hash) => {
if (users[username].hash.toString() == hash.toString()) {
res.sendStatus(200);
} else {
res.sendStatus(401);
}
});
});
```

Expand Down