cirospaciari / socketify.py

Bringing Http/Https and WebSockets High Performance servers for PyPy3 and Python3
https://www.socketify.dev
MIT License
1.4k stars 50 forks source link

Architecture Page with Reference to corking process/procedure/concept #51

Open bsenftner opened 1 year ago

bsenftner commented 1 year ago

Long C/C++ term developer (44 years) with only 2 years professional Python experience...

I am unfamiliar with this "corking" concept, web searching leads me to an authentication library for the Bottle Framework. https://cork.readthedocs.io/en/latest/

Can a reference to this specific "Corking" concept be supplied? The documentation page about corking says a lot without describing what the concept actually is, and I'm left confused.

Note: I am a high compute developer, tending to work on projects requiring high compute + high bandwidth. I typically write REST servers in C++ using either the Restino or Restbed C++ frameworks. However, it looks like the majority of REST development jobs are in Python. So I've been learning the various Python REST libs. I just discovered socketify.py this morning, and it looks very promising. Most my Python REST experience is with FastAPI.

cirospaciari commented 1 year ago

I will improve the Docs, but i will also work to improve auto-corking, in near future i will create an full architecture page in the docs. At this moment i'm working in ASGI and WSGI CLI tools and docs, and i will provide also examples of socketify.py powering FastAPI, Flask, Django, Falcon and Emmett

cirospaciari commented 1 year ago

I will keep this Issue Open, so you can follow the progress here, If you want do dive in the C++ source code, the original repository for the C++ base is https://github.com/uNetworking/uWebSockets and my fork is https://github.com/cirospaciari/uWebSockets/tree/capi-complete-with-ssl-and-samples

bsenftner commented 1 year ago

Thank you and following your guidance. (I'm quite impressed!)

cirospaciari commented 1 year ago

Thank you and following your guidance. (I'm quite impressed!)

Thanks for the compliments, i will always try my best to keeping improving, i hope more awesome people like you, discover socketify.py project, community is really important :heart:

bsenftner commented 1 year ago

Perhaps useful, I tried asking ChatGPT about corking. This being only my 2nd try using ChatGPT, wow... unless this is completely wrong, as I have heard ChatGPT can be like an arrogant 8 year old, confidently wrong... Is this your "corking"?

me: In network communication software there is a concept called "corking". What is this "corking"? Is it a type of process?

ChatGPT: In network communication, "corking" is a term that refers to the process of holding back the transmission of data until a certain amount of data has been accumulated, or until a certain event occurs. This can be useful for optimizing network performance and reducing network congestion. For example, a network socket may be "corked" until a certain amount of data has been accumulated in a buffer, at which point the data can be sent in a single, larger packet, rather than multiple smaller packets. This can help to reduce the number of packets that need to be sent over the network, which can improve performance.

me: What are examples of correct corking and incorrect corking when writing code for the uWebSockets c++ network library.

ChatGPT: Correct corking when writing code for the uWebSockets C++ network library would involve using the appropriate methods and functions provided by the library to hold back the transmission of data until a certain amount of data has been accumulated, or until a certain event occurs. For example, the send method of the uWS::WebSocket class can be used to transmit data over a network socket. This method has an optional cork parameter that can be set to true to enable corking. In this case, the data that is passed to the send method will be held in a buffer until a certain amount of data has been accumulated, or until a certain event occurs, at which point the data will be transmitted in a single packet.

Incorrect corking when using the uWebSockets C++ network library would involve using the wrong methods or functions for holding back the transmission of data, or not using the appropriate settings or parameters to enable corking. For example, if the send method is called without setting the cork parameter to true, then corking will not be enabled, and the data will be transmitted immediately, rather than being held in a buffer. This can result in poor performance and network congestion.

cirospaciari commented 1 year ago

I think this is pretty accurate, but i want to write some doc about it and send to the author of uWebSockets to confirm this, but at least with my current understand of corking, this is accurate

cirospaciari commented 1 year ago

@bsenftner to resume all your text and also to add the text of the official uWebSockets docs, corking is packing many sends into one single syscall/SSL block, so is basically and optimization, your code should work fine without corking but may have an performance penalty, in my tests corking helps a LOT, i always will recommend to cork after the first await call in async, before this auto corking is enabled, and in sync calls will also auto cork.

https://unetworking.github.io/uWebSockets.js/generated/interfaces/WebSocket.html#cork https://github.com/uNetworking/uWebSockets/blob/master/misc/READMORE.md

cirospaciari commented 1 year ago

I added this resume to the docs, but I think an Architecture Page is still needed, not only to show corking but new upcoming cache tools too https://github.com/cirospaciari/socketify.py/issues/60!

https://docs.socketify.dev/corking.html