Proper usage of Corking for best performance with uWebsockets.js #909
Replies: 8 comments 15 replies
-
Did you look at the User Manual? It explains everything you need to know in detail: https://github.com/uNetworking/uWebSockets/blob/master/misc/READMORE.md#corking |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Alright I have a semi-good solution that allows shipping this in v20 right now. Ideally I want a termination of the app on wrong use, but that would break semver minor. So what I am going to do is just add stderror prints warning of ill-use whenever they happen. This is backwards compatible yet makes it obvious when wrong usage is made |
Beta Was this translation helpful? Give feedback.
-
Waiting for CI, will release this so you can see for yourself when you get warnings |
Beta Was this translation helpful? Give feedback.
-
Have made some fixes; write and tryEnd are not required to be corked, as there are cases where calling them outside of a cork is the best (such as when continuing a large write from onWritable, or anywhere else. Ideally the warning would be better at knowing exactly when it's ill-use but for now I just have to remove tryEnd, write from the checks. Will make a new release when CI finishes |
Beta Was this translation helpful? Give feedback.
-
No, I have done some thinking and .write and .tryEnd should also, always be corked. It might looks ridiculous in some cases such as this one:
but it is always better to be ridiculously corked, than not. The whole idea is telling the lib that "I'm going to write now". Sure, the naming could be changed from "cork" to "collect" and then we can add a special case "collectOne" for cases where there will only be 1 write. But it is always better to just be corked, as the library will internally pick whether to actually cork it or not. For instance large sends never go to cork buffer regardless of being corked or not, so in cases where you want to send big amounts of data, being corked will just be a bureaucratic detail. That's why it is inherently impossible to expose uWS.js as Express interface or similar, since Express has no concept of corking, while it is a core concept of uWS - with this warning this concept only becomes more obvious and it always has been this central only that people don't give a shit about reading the user manual. |
Beta Was this translation helpful? Give feedback.
-
how would you use this required corking in combination with .onWritable()? Since .cork takes a callback function I cant return to the writable what I got from .write() or .tryEnd(). Either Im tired or thats just not possible? |
Beta Was this translation helpful? Give feedback.
-
This discussion led me to read the manual. I must say, thank you. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I was looking to improve the performance of the hyper-express implementation on top of uWebsockets.js and realized that I am not properly corking the responses for best performance.
From what I have been able to gather from looking at issues, discussions and other resources in this respository, It seems that for responses which are sent synchronously before uWS.HttpRequest is returned, uWebsockets.js automatically corks the response. However, for when a .onAborted() callback is bound and the response is sent asynchronously, corking is not done automatically and should be done before sending the response asynchronously.
Based on the above information, I had the following questions:
I apologize If any of the above questions may have been answered somewhere else in the resources for this repository but was hoping to get a very fine tuned use case for corking so it can be best implemented.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions