Skip to content

Commit 3fcfad9

Browse files
author
John Jardin
committed
Initial Upload
0 parents  commit 3fcfad9

16 files changed

+1769
-0
lines changed

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const TIMEOUT_MS = 10
2+
3+
console.log('Root Code - START')
4+
5+
setTimeout(() => { console.log('--Timeout') }, TIMEOUT_MS)
6+
7+
console.log('Root Code - END - Event Loop Takes Over')
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const TIMEOUT_MS = 0
2+
3+
console.log('Root Code - START')
4+
5+
setTimeout(() => { console.log('--Timeout 1') }, TIMEOUT_MS)
6+
setImmediate(() => { console.log('--Immediate 1') })
7+
8+
setTimeout(() => {
9+
setTimeout(() => { console.log('--Timeout 3') }, TIMEOUT_MS)
10+
setImmediate(() => { console.log('--Immediate 2') })
11+
12+
console.log('--Timeout 2')
13+
}, TIMEOUT_MS)
14+
15+
console.log('Root Code - END - Event Loop Takes Over')
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const TIMEOUT_MS = 10
2+
3+
console.log('Root Code - START')
4+
5+
setTimeout(() => { console.log('--Timeout 1') }, TIMEOUT_MS)
6+
setImmediate(() => { console.log('--Immediate 1') })
7+
8+
setTimeout(() => {
9+
setTimeout(() => { console.log('--Timeout 3') }, TIMEOUT_MS)
10+
setImmediate(() => { console.log('--Immediate 2') })
11+
12+
console.log('--Timeout 2')
13+
}, TIMEOUT_MS)
14+
15+
// process.nextTick(() => { console.log('--Next Tick 1') })
16+
17+
process.nextTick(() => {
18+
process.nextTick(() => { console.log('--Next Tick 2') })
19+
console.log('--Next Tick 1')
20+
})
21+
22+
console.log('Root Code - END - Event Loop Takes Over')
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const TIMEOUT_MS = 10
2+
3+
console.log('Root Code - START')
4+
5+
setImmediate(() => {
6+
console.log('--Immediate 1')
7+
process.nextTick(() => { console.log('--Next Tick 2') })
8+
})
9+
10+
setTimeout(() => {
11+
Promise.resolve().then(x => { console.log('--Promise 2') })
12+
setTimeout(() => { console.log('--Timeout 3') }, TIMEOUT_MS)
13+
setImmediate(() => { console.log('--Immediate 2') })
14+
process.nextTick(() => { console.log('--Next Tick 3') })
15+
16+
console.log('--Timeout 1')
17+
}, TIMEOUT_MS)
18+
19+
Promise.resolve().then(x => { console.log('--Promise 1') })
20+
process.nextTick(() => { console.log('--Next Tick 1') })
21+
22+
console.log('Root Code - END - Event Loop Takes Over')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
const AsyncHooks = require('async_hooks')
4+
const FS = require('fs')
5+
const TIMEOUT_MS = 10
6+
7+
// ASYNC TRACKER
8+
AsyncHooks.createHook({
9+
init (asyncId, type, triggerAsyncId) {
10+
const id = AsyncHooks.executionAsyncId()
11+
FS.writeSync(1, `- ${type}(${asyncId}): trigger: ${triggerAsyncId} execution: ${id}\n`)
12+
}
13+
}).enable()
14+
15+
// TEST FUNCTIONS
16+
setTimeout(() => {}, TIMEOUT_MS)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict'
2+
3+
const { AsyncDebugger } = require('../lib/async-debugger')
4+
const TIMEOUT_MS = 10
5+
const INTERVAL_MS = 2000
6+
const asyncDebugger = new AsyncDebugger()
7+
8+
// TEST FUNCTIONS
9+
const testTimeout = () => {
10+
setTimeout(() => {}, TIMEOUT_MS)
11+
}
12+
13+
const testInterval = () => {
14+
setInterval(() => { console.log('I am an Interval') }, INTERVAL_MS)
15+
}
16+
17+
const testImmediate = () => {
18+
setImmediate(() => {})
19+
}
20+
21+
const testNextTick = () => {
22+
process.nextTick(() => {})
23+
}
24+
25+
const testAsyncFunction = async () => {}
26+
27+
const testPromise = () => {
28+
new Promise((resolve) => resolve(true)).then((a) => {})
29+
}
30+
31+
const testConsoleLog = () => {
32+
console.log('I am a Console Log')
33+
}
34+
35+
// ASYNC TRACKER
36+
asyncDebugger.startTracking('Test', testNextTick)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict'
2+
3+
const FS = require('fs')
4+
const Path = require('path')
5+
const { AsyncDebugger } = require('../lib/async-debugger')
6+
const asyncDebugger = new AsyncDebugger()
7+
8+
// TEST FUNCTIONS
9+
const testReadFile = () => {
10+
FS.readFile(Path.join(__dirname, '../package.json'), () => {})
11+
}
12+
13+
// ASYNC TRACKER
14+
asyncDebugger.startTracking('Test', testReadFile)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict'
2+
3+
const Axios = require('axios')
4+
const Mongoose = require('mongoose')
5+
const BCrypt = require('bcrypt')
6+
const { AsyncDebugger } = require('../lib/async-debugger')
7+
const asyncDebugger = new AsyncDebugger()
8+
9+
// TEST FUNCTIONS
10+
const testHTTP = async () => {
11+
await Axios.get('https://agilite.io')
12+
}
13+
14+
const testMongo = async () => {
15+
await Mongoose.connect('mongodb://localhost/test')
16+
Mongoose.disconnect()
17+
}
18+
19+
const testBCrypt = () => {
20+
const saltRounds = 10
21+
const myPlaintextPassword = 'changemenow'
22+
23+
BCrypt.genSalt(saltRounds, (err, salt) => {
24+
if (err) return false
25+
26+
BCrypt.hash(myPlaintextPassword, salt, (err, hash) => {
27+
if (err) return false
28+
})
29+
})
30+
}
31+
32+
// ASYNC TRACKER
33+
asyncDebugger.startTracking('Test', testHTTP)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
const Axios = require('axios')
4+
const { AsyncDebugger } = require('../lib/async-debugger')
5+
const asyncDebugger = new AsyncDebugger()
6+
7+
// TEST FUNCTIONS
8+
const testCustomFetch = () => {
9+
_testCustomFetchExtended1()
10+
}
11+
12+
// PRIVATE FUNCTIONS
13+
const _testCustomFetchExtended1 = () => {
14+
let x = 0
15+
const y = 10
16+
17+
for (; x < y; x++) console.log('Test')
18+
_testCustomFetchExtended2()
19+
}
20+
21+
const _testCustomFetchExtended2 = async () => {
22+
await Axios.get('https://agilite.io')
23+
}
24+
25+
// ASYNC TRACKER
26+
asyncDebugger.startTracking('Test', testCustomFetch)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Agilit-e
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<center><img src="./assets/bleeding-code-logo-slogan.jpg" width="400"></center>
2+
<br>
3+
4+
# nodejs-performance-optimization
5+
> Source Code for live demos via Bleeding Code tutorials
6+
7+
## Table of Contents
8+
9+
- [Project Resources](#table-of-contents)
10+
- [Testing The Event Loop Phases](#testing-the-event-loop-phases)
11+
- [What Type Of Async Function Am I Running](#what-type-of-async-function-am-i-running)
12+
- [Contributing](#contributing)
13+
- [Links](#links)
14+
- [License](#license)
15+
16+
## Testing The Event Loop Phases
17+
18+
- Watch [YouTube Video](https://youtu.be/ol56smloW2Q)
19+
- Read [Blog Post](http://bleedingcode.com/managing-the-event-loop-phases/)
20+
- Source Code Folder: [01-testing-event-loop-phases](/01-testing-event-loop-phases)
21+
22+
## What Type Of Async Function Am I Running
23+
24+
- Watch [YouTube Video](https://youtu.be/ol56smloW2Q)
25+
- Read [Blog Post](http://bleedingcode.com/managing-the-event-loop-phases/)
26+
- Source Code Folder: [02-async-hooks-types-of-async-functions](/02-async-hooks-types-of-async-functions)
27+
28+
## Contributing
29+
30+
1. Fork it (<https://github.com/agilitehub/nodejs-performance-optimization/fork>)
31+
2. Create your feature branch (`git checkout -b feature/fooBar`)
32+
3. Commit your changes (`git commit -am 'Add some fooBar'`)
33+
4. Push to the branch (`git push origin feature/fooBar`)
34+
5. Create a new Pull Request
35+
36+
## Links
37+
38+
- Bleeding Code YouTube Channel: https://youtube.com/bleedingcode
39+
- [Subscribe to Channel](https://youtube.com/bleedingcode)
40+
- Bleeding Code On Twitter: https://twitter.com/bleedcode
41+
- Agilit-e Website: https://agilite.io
42+
43+
## License
44+
45+
Distributed under the MIT license. See ``LICENSE`` for more information.

assets/bleeding-code-logo-slogan.jpg

233 KB
Loading

0 commit comments

Comments
 (0)