René's URL Explorer Experiment


Title: Performance issue when sending large responses for concurrent requests · Issue #37680 · nodejs/node · GitHub

Open Graph Title: Performance issue when sending large responses for concurrent requests · Issue #37680 · nodejs/node

X Title: Performance issue when sending large responses for concurrent requests · Issue #37680 · nodejs/node

Description: Version: 12.20.1 Platform: Linux xxx 5.4.0-1038-aws #4018.04.1-Ubuntu SMP Sat Feb 6 01:56:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux, or Darwin xxx 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.161/...

Open Graph Description: Version: 12.20.1 Platform: Linux xxx 5.4.0-1038-aws #4018.04.1-Ubuntu SMP Sat Feb 6 01:56:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux, or Darwin xxx 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 2...

X Description: Version: 12.20.1 Platform: Linux xxx 5.4.0-1038-aws #4018.04.1-Ubuntu SMP Sat Feb 6 01:56:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux, or Darwin xxx 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 2...

Opengraph URL: https://github.com/nodejs/node/issues/37680

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Performance issue when sending large responses for concurrent requests","articleBody":"\u003c!--\r\nThank you for reporting an issue.\r\n\r\nThis issue tracker is for bugs and issues found within Node.js core.\r\nIf you require more general support please file an issue on our help\r\nrepo. https://github.com/nodejs/help\r\n\r\n\r\nPlease fill in as much of the template below as you're able.\r\n\r\nVersion: output of `node -v`\r\nPlatform: output of `uname -a` (UNIX), or output of `\"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { \"x64\" } else { \"x86\" })\"` in PowerShell console (Windows)\r\nSubsystem: if known, please specify affected core module name\r\n--\u003e\r\n\r\n* **Version**: 12.20.1\r\n* **Platform**: Linux xxx 5.4.0-1038-aws #40~18.04.1-Ubuntu SMP Sat Feb 6 01:56:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux, or Darwin xxx 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64\r\n* **Subsystem**:\r\n\r\n### What steps will reproduce the bug?\r\n\r\n\u003c!--\r\nEnter details about your bug, preferably a simple code snippet that can be\r\nrun using `node` directly without installing third-party dependencies.\r\n--\u003e\r\n\r\n```\r\nconst express = require(\"express\");\r\n\r\nfunction makeBigObject(leaves, depth) {\r\n  if (depth === 0) {\r\n    return \"howdy\";\r\n  } else {\r\n    const ret = {};\r\n    for (let i = 0; i \u003c leaves; ++i) {\r\n      ret[i] = makeBigObject(leaves, depth - 1);\r\n    }\r\n    return ret;\r\n  }\r\n}\r\n\r\nfunction getTimeMs() {\r\n  return Date.now() - firstRequestStartTime;\r\n}\r\n\r\nconst app = express();\r\n\r\nconst bigObject = makeBigObject(2000, 2);\r\nlet requestCount = 0;\r\nlet firstRequestStartTime;\r\n\r\nasync function requestHandler({ requestIndex, req, res }) {\r\n  if (requestIndex === 1) {\r\n    firstRequestStartTime = Date.now();\r\n  }\r\n\r\n  console.log(\r\n    `[${getTimeMs()}] Serializing response for request ${requestIndex}...`\r\n  );\r\n  const serializedBigObject = JSON.stringify(bigObject);\r\n\r\n  const flushStartTimeMs = Date.now();\r\n  res.on(\"finish\", () =\u003e {\r\n    const flushDurationMs = Date.now() - flushStartTimeMs;\r\n    console.log(\r\n      `[${getTimeMs()}] -- Took ${flushDurationMs}ms to flush response for request ${requestIndex} --`\r\n    );\r\n  });\r\n\r\n  console.log(\r\n    `[${getTimeMs()}] Sending ${Math.round(\r\n      serializedBigObject.length / 1024 / 1024\r\n    )}MB response for request ${requestIndex}...`\r\n  );\r\n  res.send(serializedBigObject);\r\n  // res.send(\"ok\");\r\n\r\n  console.log(`[${getTimeMs()}] - Handler done for request ${requestIndex} -`);\r\n}\r\n\r\napp.get(\"/\", async (req, res) =\u003e {\r\n  const requestIndex = ++requestCount;\r\n  requestHandler({ requestIndex, req, res });\r\n});\r\n\r\napp.listen(\"/tmp/sock\", () =\u003e\r\n  console.log(`Example app listening on Unix domain socket /tmp/sock!`)\r\n);\r\n```\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nSend multiple concurrent requests to the app. For example,\r\n\r\n(for x in $(seq 5); do time curl --unix-socket /tmp/sock http://localhost/ \u003e /dev/null \u0026 done)\r\n\r\n### What is the expected behavior?\r\n\r\n\u003c!--\r\nIf possible please provide textual output instead of screenshots.\r\n--\u003e\r\n\r\nI expect that responses are flushed fairly fast and early requests don't \"wait\" for later requests to flush together\r\n\r\n[0] Processing request 1...\r\n[23] Serializing response for request 1...\r\n[390] Sending 55MB response for request 1...\r\n[536] - Handler done for request 1 -\r\n[537] Processing request 2...\r\n[547] -- Took 158ms to flush response for request 1 --\r\n[558] Serializing response for request 2...\r\n[925] Sending 55MB response for request 2...\r\n[1065] - Handler done for request 2 -\r\n[1065] Processing request 3...\r\n[1077] -- Took 152ms to flush response for request 2 --\r\n[1086] Serializing response for request 3...\r\n[1444] Sending 55MB response for request 3...\r\n[1568] - Handler done for request 3 -\r\n[1568] Processing request 4...\r\n[1579] -- Took 135ms to flush response for request 3 --\r\n[1589] Serializing response for request 4...\r\n[1948] Sending 55MB response for request 4...\r\n[2075] - Handler done for request 4 -\r\n[2075] Processing request 5...\r\n[2087] -- Took 139ms to flush response for request 4 --\r\n[2096] Serializing response for request 5...\r\n[2455] Sending 55MB response for request 5...\r\n[2581] - Handler done for request 5 -\r\n[2591] -- Took 136ms to flush response for request 5 --\r\n\r\n\r\n### What do you see instead?\r\n\r\n\u003c!--\r\nIf possible please provide textual output instead of screenshots.\r\n--\u003e\r\n\r\nEarlier requests were blocked and not making progress until the later requests finished processing/serializing. The more concurrent requests, the longer the delay and the worse the problem is.\r\n\r\n[0] Serializing response for request 1...\r\n[334] Sending 55MB response for request 1...\r\n[491] - Handler done for request 1 -\r\n[492] Serializing response for request 2...\r\n[820] Sending 55MB response for request 2...\r\n[957] - Handler done for request 2 -\r\n[958] Serializing response for request 3...\r\n[1292] Sending 55MB response for request 3...\r\n[1430] - Handler done for request 3 -\r\n[1432] Serializing response for request 4...\r\n[1763] Sending 55MB response for request 4...\r\n[1902] - Handler done for request 4 -\r\n[1910] Serializing response for request 5...\r\n[2229] Sending 55MB response for request 5...\r\n[2371] - Handler done for request 5 -\r\n[2536] -- Took 773ms to flush response for request 4 --\r\n[2538] -- Took 309ms to flush response for request 5 --\r\n[2539] -- Took 1719ms to flush response for request 2 --\r\n[2540] -- Took 2206ms to flush response for request 1 --\r\n[2540] -- Took 1248ms to flush response for request 3 --\r\n\r\n### Additional information\r\n\r\n\u003c!--\r\nTell us anything else you think we should know.\r\n--\u003e\r\n\r\nif replacing res.send(serializedBigObject) with res.send(\"ok\"), then you get expected behavior. So response size matters.\r\n\r\n[0] Serializing response for request 1...\r\n[341] Sending 55MB response for request 1...\r\n[345] - Handler done for request 1 -\r\n[346] -- Took 5ms to flush response for request 1 --\r\n[348] Serializing response for request 2...\r\n[660] Sending 55MB response for request 2...\r\n[661] - Handler done for request 2 -\r\n[661] -- Took 1ms to flush response for request 2 --\r\n[661] Serializing response for request 3...\r\n[976] Sending 55MB response for request 3...\r\n[977] - Handler done for request 3 -\r\n[977] -- Took 1ms to flush response for request 3 --\r\n[977] Serializing response for request 4...\r\n[1296] Sending 55MB response for request 4...\r\n[1297] - Handler done for request 4 -\r\n[1297] -- Took 1ms to flush response for request 4 --\r\n[1297] Serializing response for request 5...\r\n[1633] Sending 55MB response for request 5...\r\n[1633] - Handler done for request 5 -\r\n[1634] -- Took 1ms to flush response for request 5 --\r\n","author":{"url":"https://github.com/xue-cai","@type":"Person","name":"xue-cai"},"datePublished":"2021-03-09T20:28:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/37680/node/issues/37680"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:51014bc4-2e8b-a0ed-2ff3-2e886103182b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id81B4:14011B:528C0C0:74DCFE3:6A4FE83B
html-safe-nonce6e48620088ae1ee5461a70c3d225d2759cf36ec813b38a7b5cbb303e30f25479
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUI0OjE0MDExQjo1MjhDMEMwOjc0RENGRTM6NkE0RkU4M0IiLCJ2aXNpdG9yX2lkIjoiNDU1MDk5NjA4MzYxOTEyOTQwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf73ce29f17865cc35f493732b4a88e6ffa80f6f124c164b72ccf506b18782dda
hovercard-subject-tagissue:826588684
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/37680/issue_layout
twitter:imagehttps://opengraph.githubassets.com/3b61451c5d21a562fc16f43ad1dea1088cca83cf685545f3b15556cad41e6012/nodejs/node/issues/37680
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/3b61451c5d21a562fc16f43ad1dea1088cca83cf685545f3b15556cad41e6012/nodejs/node/issues/37680
og:image:altVersion: 12.20.1 Platform: Linux xxx 5.4.0-1038-aws #4018.04.1-Ubuntu SMP Sat Feb 6 01:56:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux, or Darwin xxx 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 2...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamexue-cai
hostnamegithub.com
expected-hostnamegithub.com
None19b98c3d9767bb8a56238a89ff8401d1cbdf3bc5c353799aacf49fe6c76b4b7c
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release142593e66413bbae27fd485859993597d5a3b104
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nodejs/node/issues/37680#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F37680
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F37680
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/37680
Reloadhttps://github.com/nodejs/node/issues/37680
Reloadhttps://github.com/nodejs/node/issues/37680
Please reload this pagehttps://github.com/nodejs/node/issues/37680
nodejs https://github.com/nodejs
nodehttps://github.com/nodejs/node
Please reload this pagehttps://github.com/nodejs/node/issues/37680
Notifications https://github.com/login?return_to=%2Fnodejs%2Fnode
Fork 36k https://github.com/login?return_to=%2Fnodejs%2Fnode
Star 118k https://github.com/login?return_to=%2Fnodejs%2Fnode
Code https://github.com/nodejs/node
Issues 1.3k https://github.com/nodejs/node/issues
Pull requests 976 https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality 0 https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Code https://github.com/nodejs/node
Issues https://github.com/nodejs/node/issues
Pull requests https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Performance issue when sending large responses for concurrent requestshttps://github.com/nodejs/node/issues/37680#top
questionIssues that look for answers.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22question%22
stalehttps://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stale%22
https://github.com/xue-cai
xue-caihttps://github.com/xue-cai
on Mar 9, 2021https://github.com/nodejs/node/issues/37680#issue-826588684
Working with nvm, nvmw and similar installation managers #40https://github.com/nodejs/node/issues/40
http://localhost/http://localhost/
questionIssues that look for answers.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22question%22
stalehttps://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stale%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.