How to measure Event loop blocking in Nodejs?How to detect and measure event loop blocking in node.js?How does database indexing work?How can I upload files asynchronously?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How to exit in Node.jsHow can I update NodeJS and NPM to the next versions?Measure time elapsed in Python?Why are elementwise additions much faster in separate loops than in a combined loop?How do I return the response from an asynchronous call?
Building a Shader Switch | How to get custom values from individual objects?
ArcPy Delete Function not working inside for loop?
How should one refer to knights (& dames) in academic writing?
Interviewing with an unmentioned 9 months of sick leave taken during a job
Cover a cube with four-legged walky-squares!
Is it okay for a chapter's POV to shift as it progresses?
What are the first usages of "thong" as a wearable item of clothing, both on the feet and on the waist?
Why do so many pure math PhD students drop out or leave academia, compared to applied mathematics PhDs?
FPGA CPUs, how to find the max speed?
Sending a photo of my bank account card to the future employer
How possible is a successful landing just with 1 wing?
Will this tire fail its MOT?
Pi 3 B+ no audio device found
Random piece of plastic
pg_ctl hangs over ssh
Does the Intel 8085 CPU use real memory addresses?
Get node ID or URL in Twig on field level
How to color a tag in a math equation?
What are the arguments for California’s nonpartisan blanket (jungle) primaries?
Why doesn't philosophy have higher standards for its arguments?
How can the electric potential be zero at a point where the electric field isn't, if that field can give a test charge kinetic energy?
How can a drink contain 1.8 kcal energy while 0 g fat/carbs/protein?
What impact would a dragon the size of Asia have on the environment?
Is it inertia which causes a rotating object to rotate forever without external force?
How to measure Event loop blocking in Nodejs?
How to detect and measure event loop blocking in node.js?How does database indexing work?How can I upload files asynchronously?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How to exit in Node.jsHow can I update NodeJS and NPM to the next versions?Measure time elapsed in Python?Why are elementwise additions much faster in separate loops than in a combined loop?How do I return the response from an asynchronous call?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I can't get real an event loop blocking time. I have searched in Google answers (here), but they didn't help for me. I got different results.
I have created Node/Express app. And try to detect event loop blocking with different tools. I used hrtime, pm2, blocked_at.
1 test:
server.js
require('./routes')(app, passport, mongoData)
routes/index.js
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const blockedAt = require('blocked-at')
blockedAt((time, stack) =>
console.log(`Blocked for $timems, operation started here:`, stack)
, threshold:12)
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random()
let ArticleController = require(path + 'app/controllers/ArticleController')
let articleController = new ArticleController()
articleController.index(req, res, next)
)
I got:
Blocked for 15.5994921875ms, operation started here: [ ' at ',
' at ArticleService.getArticle (/app/services/article/ArticleService.js:79:44)' ]
Blocked for 14.0350537109375ms, operation started here: [ ' at Promise.then ()',
' at ExpressHandlebars.render (node_modules/express-handlebars/lib/express-handlebars.js:157:8)',
' at ExpressHandlebars. (node_modules/express-handlebars/lib/express-handlebars.js:226:29)' ]
But nothing about my blocking script!
2 test:
With pm2:
- Event Loop Latency - 0.56ms
- Event Loop Latency p95 - 4.5ms
After remove my blocking script I get same results.
3 test:
With hrtime I measure inside ArticleController.index. Index method loads 3 services in async mode. There are a lot of I/O operations, and there works worker_threads. Some code created into setImmediate.
inside into index:
let hrstart = process.hrtime()
// there works all my services
//...
let hrend = process.hrtime(hrstart)
console.info('Execution time (hr): %ds ir ms: %dms', hrend[0], hrend[1] / 1000000)
res.render('home', data)
There I got 1s, 233ms. I got big time, but I confused - because there all operations work in async mode, Event loop ain't blocking?
How I can measure Event loop blocks?
I expect the output: "event loop blocking in routes/index.js:12 for 5000ms", but actual output doesn't catch my blocking script.
node.js performance asynchronous nonblocking
add a comment |
I can't get real an event loop blocking time. I have searched in Google answers (here), but they didn't help for me. I got different results.
I have created Node/Express app. And try to detect event loop blocking with different tools. I used hrtime, pm2, blocked_at.
1 test:
server.js
require('./routes')(app, passport, mongoData)
routes/index.js
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const blockedAt = require('blocked-at')
blockedAt((time, stack) =>
console.log(`Blocked for $timems, operation started here:`, stack)
, threshold:12)
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random()
let ArticleController = require(path + 'app/controllers/ArticleController')
let articleController = new ArticleController()
articleController.index(req, res, next)
)
I got:
Blocked for 15.5994921875ms, operation started here: [ ' at ',
' at ArticleService.getArticle (/app/services/article/ArticleService.js:79:44)' ]
Blocked for 14.0350537109375ms, operation started here: [ ' at Promise.then ()',
' at ExpressHandlebars.render (node_modules/express-handlebars/lib/express-handlebars.js:157:8)',
' at ExpressHandlebars. (node_modules/express-handlebars/lib/express-handlebars.js:226:29)' ]
But nothing about my blocking script!
2 test:
With pm2:
- Event Loop Latency - 0.56ms
- Event Loop Latency p95 - 4.5ms
After remove my blocking script I get same results.
3 test:
With hrtime I measure inside ArticleController.index. Index method loads 3 services in async mode. There are a lot of I/O operations, and there works worker_threads. Some code created into setImmediate.
inside into index:
let hrstart = process.hrtime()
// there works all my services
//...
let hrend = process.hrtime(hrstart)
console.info('Execution time (hr): %ds ir ms: %dms', hrend[0], hrend[1] / 1000000)
res.render('home', data)
There I got 1s, 233ms. I got big time, but I confused - because there all operations work in async mode, Event loop ain't blocking?
How I can measure Event loop blocks?
I expect the output: "event loop blocking in routes/index.js:12 for 5000ms", but actual output doesn't catch my blocking script.
node.js performance asynchronous nonblocking
add a comment |
I can't get real an event loop blocking time. I have searched in Google answers (here), but they didn't help for me. I got different results.
I have created Node/Express app. And try to detect event loop blocking with different tools. I used hrtime, pm2, blocked_at.
1 test:
server.js
require('./routes')(app, passport, mongoData)
routes/index.js
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const blockedAt = require('blocked-at')
blockedAt((time, stack) =>
console.log(`Blocked for $timems, operation started here:`, stack)
, threshold:12)
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random()
let ArticleController = require(path + 'app/controllers/ArticleController')
let articleController = new ArticleController()
articleController.index(req, res, next)
)
I got:
Blocked for 15.5994921875ms, operation started here: [ ' at ',
' at ArticleService.getArticle (/app/services/article/ArticleService.js:79:44)' ]
Blocked for 14.0350537109375ms, operation started here: [ ' at Promise.then ()',
' at ExpressHandlebars.render (node_modules/express-handlebars/lib/express-handlebars.js:157:8)',
' at ExpressHandlebars. (node_modules/express-handlebars/lib/express-handlebars.js:226:29)' ]
But nothing about my blocking script!
2 test:
With pm2:
- Event Loop Latency - 0.56ms
- Event Loop Latency p95 - 4.5ms
After remove my blocking script I get same results.
3 test:
With hrtime I measure inside ArticleController.index. Index method loads 3 services in async mode. There are a lot of I/O operations, and there works worker_threads. Some code created into setImmediate.
inside into index:
let hrstart = process.hrtime()
// there works all my services
//...
let hrend = process.hrtime(hrstart)
console.info('Execution time (hr): %ds ir ms: %dms', hrend[0], hrend[1] / 1000000)
res.render('home', data)
There I got 1s, 233ms. I got big time, but I confused - because there all operations work in async mode, Event loop ain't blocking?
How I can measure Event loop blocks?
I expect the output: "event loop blocking in routes/index.js:12 for 5000ms", but actual output doesn't catch my blocking script.
node.js performance asynchronous nonblocking
I can't get real an event loop blocking time. I have searched in Google answers (here), but they didn't help for me. I got different results.
I have created Node/Express app. And try to detect event loop blocking with different tools. I used hrtime, pm2, blocked_at.
1 test:
server.js
require('./routes')(app, passport, mongoData)
routes/index.js
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const blockedAt = require('blocked-at')
blockedAt((time, stack) =>
console.log(`Blocked for $timems, operation started here:`, stack)
, threshold:12)
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random()
let ArticleController = require(path + 'app/controllers/ArticleController')
let articleController = new ArticleController()
articleController.index(req, res, next)
)
I got:
Blocked for 15.5994921875ms, operation started here: [ ' at ',
' at ArticleService.getArticle (/app/services/article/ArticleService.js:79:44)' ]
Blocked for 14.0350537109375ms, operation started here: [ ' at Promise.then ()',
' at ExpressHandlebars.render (node_modules/express-handlebars/lib/express-handlebars.js:157:8)',
' at ExpressHandlebars. (node_modules/express-handlebars/lib/express-handlebars.js:226:29)' ]
But nothing about my blocking script!
2 test:
With pm2:
- Event Loop Latency - 0.56ms
- Event Loop Latency p95 - 4.5ms
After remove my blocking script I get same results.
3 test:
With hrtime I measure inside ArticleController.index. Index method loads 3 services in async mode. There are a lot of I/O operations, and there works worker_threads. Some code created into setImmediate.
inside into index:
let hrstart = process.hrtime()
// there works all my services
//...
let hrend = process.hrtime(hrstart)
console.info('Execution time (hr): %ds ir ms: %dms', hrend[0], hrend[1] / 1000000)
res.render('home', data)
There I got 1s, 233ms. I got big time, but I confused - because there all operations work in async mode, Event loop ain't blocking?
How I can measure Event loop blocks?
I expect the output: "event loop blocking in routes/index.js:12 for 5000ms", but actual output doesn't catch my blocking script.
node.js performance asynchronous nonblocking
node.js performance asynchronous nonblocking
asked Mar 26 at 8:56
hdoitchdoitc
112 bronze badges
112 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The amount of time you block the event loop is the amount of time you spend sequentially processing. Which for your example will be the body of that function. So you could just time that and add it on to a variable.
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = new Date().getTime();
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random() ;
let ArticleController = require(path + 'app/controllers/ArticleController');
let articleController = new ArticleController();
articleController.index(req, res, next);
const total = new Date().getTime() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
You can also use the Node perf_hooks for high resolution timing.
const performance = require('perf_hooks');
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = performance.now();
// Do stuff
const total = performance.now() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
I got: Blocked for 621.9093132019043. Total blocked time is 621.9093132019043. It is bad performace, isn't it? Good performance will be about 50ms, aren't it?
– hdoitc
Mar 26 at 10:45
1
It's not great. But you do have a loop that runs 1 billion times!!
– Joey Ciechanowicz
Mar 26 at 10:54
1
Yes, I found, now: Blocked for 3.3080978393554688.
– hdoitc
Mar 26 at 10:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353127%2fhow-to-measure-event-loop-blocking-in-nodejs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The amount of time you block the event loop is the amount of time you spend sequentially processing. Which for your example will be the body of that function. So you could just time that and add it on to a variable.
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = new Date().getTime();
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random() ;
let ArticleController = require(path + 'app/controllers/ArticleController');
let articleController = new ArticleController();
articleController.index(req, res, next);
const total = new Date().getTime() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
You can also use the Node perf_hooks for high resolution timing.
const performance = require('perf_hooks');
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = performance.now();
// Do stuff
const total = performance.now() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
I got: Blocked for 621.9093132019043. Total blocked time is 621.9093132019043. It is bad performace, isn't it? Good performance will be about 50ms, aren't it?
– hdoitc
Mar 26 at 10:45
1
It's not great. But you do have a loop that runs 1 billion times!!
– Joey Ciechanowicz
Mar 26 at 10:54
1
Yes, I found, now: Blocked for 3.3080978393554688.
– hdoitc
Mar 26 at 10:58
add a comment |
The amount of time you block the event loop is the amount of time you spend sequentially processing. Which for your example will be the body of that function. So you could just time that and add it on to a variable.
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = new Date().getTime();
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random() ;
let ArticleController = require(path + 'app/controllers/ArticleController');
let articleController = new ArticleController();
articleController.index(req, res, next);
const total = new Date().getTime() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
You can also use the Node perf_hooks for high resolution timing.
const performance = require('perf_hooks');
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = performance.now();
// Do stuff
const total = performance.now() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
I got: Blocked for 621.9093132019043. Total blocked time is 621.9093132019043. It is bad performace, isn't it? Good performance will be about 50ms, aren't it?
– hdoitc
Mar 26 at 10:45
1
It's not great. But you do have a loop that runs 1 billion times!!
– Joey Ciechanowicz
Mar 26 at 10:54
1
Yes, I found, now: Blocked for 3.3080978393554688.
– hdoitc
Mar 26 at 10:58
add a comment |
The amount of time you block the event loop is the amount of time you spend sequentially processing. Which for your example will be the body of that function. So you could just time that and add it on to a variable.
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = new Date().getTime();
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random() ;
let ArticleController = require(path + 'app/controllers/ArticleController');
let articleController = new ArticleController();
articleController.index(req, res, next);
const total = new Date().getTime() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
You can also use the Node perf_hooks for high resolution timing.
const performance = require('perf_hooks');
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = performance.now();
// Do stuff
const total = performance.now() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
The amount of time you block the event loop is the amount of time you spend sequentially processing. Which for your example will be the body of that function. So you could just time that and add it on to a variable.
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = new Date().getTime();
// my blocking script
for (let i = 0; i <= 1000000000; i++)
let z = 10000 / Math.random() ;
let ArticleController = require(path + 'app/controllers/ArticleController');
let articleController = new ArticleController();
articleController.index(req, res, next);
const total = new Date().getTime() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
You can also use the Node perf_hooks for high resolution timing.
const performance = require('perf_hooks');
let totalBlocked = 0;
router
.get('/articles/:articleId(\d+)', (req, res, next) =>
const start = performance.now();
// Do stuff
const total = performance.now() - start;
totalBlocked += total;
console.log(`Blocked for $total. Total blocked time is $totalBlocked`);
);
answered Mar 26 at 9:08
Joey CiechanowiczJoey Ciechanowicz
2,3313 gold badges16 silver badges45 bronze badges
2,3313 gold badges16 silver badges45 bronze badges
I got: Blocked for 621.9093132019043. Total blocked time is 621.9093132019043. It is bad performace, isn't it? Good performance will be about 50ms, aren't it?
– hdoitc
Mar 26 at 10:45
1
It's not great. But you do have a loop that runs 1 billion times!!
– Joey Ciechanowicz
Mar 26 at 10:54
1
Yes, I found, now: Blocked for 3.3080978393554688.
– hdoitc
Mar 26 at 10:58
add a comment |
I got: Blocked for 621.9093132019043. Total blocked time is 621.9093132019043. It is bad performace, isn't it? Good performance will be about 50ms, aren't it?
– hdoitc
Mar 26 at 10:45
1
It's not great. But you do have a loop that runs 1 billion times!!
– Joey Ciechanowicz
Mar 26 at 10:54
1
Yes, I found, now: Blocked for 3.3080978393554688.
– hdoitc
Mar 26 at 10:58
I got: Blocked for 621.9093132019043. Total blocked time is 621.9093132019043. It is bad performace, isn't it? Good performance will be about 50ms, aren't it?
– hdoitc
Mar 26 at 10:45
I got: Blocked for 621.9093132019043. Total blocked time is 621.9093132019043. It is bad performace, isn't it? Good performance will be about 50ms, aren't it?
– hdoitc
Mar 26 at 10:45
1
1
It's not great. But you do have a loop that runs 1 billion times!!
– Joey Ciechanowicz
Mar 26 at 10:54
It's not great. But you do have a loop that runs 1 billion times!!
– Joey Ciechanowicz
Mar 26 at 10:54
1
1
Yes, I found, now: Blocked for 3.3080978393554688.
– hdoitc
Mar 26 at 10:58
Yes, I found, now: Blocked for 3.3080978393554688.
– hdoitc
Mar 26 at 10:58
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353127%2fhow-to-measure-event-loop-blocking-in-nodejs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown