-
Notifications
You must be signed in to change notification settings - Fork 284
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
WebSocket Data Transfer Slows Down After Node.js 16.14.2 Release #4464
Comments
Hi! Could you host a minimal reproduction script in a GitHub repository, rather than providing an archive? |
Steps to simulate the issue: (GitHub repository: nodetesting)
|
@RedYetiDev ^ I hope these steps will help simulate the performance issue in WebSocket data transfer. |
@RedYetiDev Created a git repo with the above steps: https://github.com/harendrasp/nodetesting/tree/main |
Can you reproduce using the native websocket, and not the the WS library? Additionally, can you reproduce without Google chrome, having the client and server in the same file? |
@RedYetiDev Browser as Client, Local WebSocket Server: Conclusion: Additionally, I've observed that the browser as client performance has been slower since the release of Node.js 17.2.0 through Node.js 18.20.4. |
@RedYetiDev Does Node.js provide a native WebSocket implementation, or do I need to create one using the http module? |
Node.js provides a native WebSocket. Depending on the version, it may need to be enabled with |
@RedYetiDev |
If it's reproducible in the native websocket implementation, it has to do with the undici version present. |
In native WebSocket, the issue is reproducible starting from Node.js 20, whereas Node.js 18 performs similarly to Node.js 16 |
In the browser, the issue is reproducible starting from Node.js 17, but it has improved in Node.js 20. |
@RedYetiDev Are there any workarounds to improve performance in Node.js 18, such as configuration changes or downgrading the undici library? |
I'm not sure about workarounds, but @nodejs/undici might know. |
@RedYetiDev I've reported a bug for undici. I see the undici library was introduced in Node.js 18 however, the slowness issue actually originates from Node.js 17.2.0. |
cc @lpinca |
For reference, the undici issue is nodejs/undici#3455 |
It has nothing to do with undici if the issue can be reproduces without its WebSocket implementation. I think the difference is caused by different V8 and libuv versions (I guess the |
@lpinca Agree node 22 is giving similar performance as 16. However, Upgrading directly to Node.js 22 may lead to compatibility issues, as some libraries and dependencies might not yet fully support this version. For example, tools like Microsoft/Rush may not be compatible with Node.js 22 at the time of your upgrade. Since it can be challenging to ensure all dependent libraries are updated to match the latest Node.js version, it is advisable to consider upgrading to Node.js 18 or 20 first. |
I don't think there is much to do for us. If the "fix" for this was backportable, it would have been packported already/or it is incoming to v20 in the latest release. If it's a semver-major change (like a V8 update), it might be impossible to backport. In other terms, I don't think there is a volunteer for doing all this work right now, considering that v22 has it fixed already. |
Node.js Version
18.20.4
NPM Version
10.7.0
Operating System
ubuntu 22.04
Subsystem
buffer, events, process, stream, v8
Description
Data transfer of 4K frames (3840 * 2160 * 3) via WebSocket has become significantly slower in Node.js 18.20.4. I set up a WebSocket server, and from the browser, established a connection to transfer 4K frames. When comparing the performance of data transfer between Node.js 16.14.2 and 18.20.4, there is a noticeable degradation in transfer speed.
I'm not certain where the issue lies within the Node.js subsystems, so I've tagged multiple areas that I believe could be relevant.
Minimal Reproduction
Steps to Simulate the Issue:
Please note that same websocket version is used for both node js versions.
Archive 2.zip
Output
Output Comparison:
Node 16.14.2: Round-trip time: 220 ms
Node 18.20.4: Round-trip time: 400 ms
This indicates that Node.js 16 has a better WebSocket transfer speed compared to Node.js 18. The slowdown is consistent from Node.js 17.2.0 through Node.js 18.20.4. Although the performance improves in Node.js 19 and Node.js 20, there is still a noticeable degradation. Specifically, Node.js 19 onwards is approximately 20% slower than Node.js 16, while Node.js 18 is 100% slower compared to Node.js 16.
Before You Submit
The text was updated successfully, but these errors were encountered: