"i need 3 monitors"
"i need a mechanical keyboard"
"i need noise cancelling headphones"
Linus Torvalds, creator of the Linux operating system's, setup:
A web application can be choked by chrome’s HTTP/1.1 six connection per domain limit.
The browser creates a TCP connection to the HTTP server on port 443. As part of TLS encryption the protocol negotiation happens which will decide whether the communication will happen on HTTP/1.1 or HTTP/2, h1 or h2 for short. This is done through the ALPN TLS extension.
If the web server doesn’t support h2 whether it h2 was disabled on purpose, or just not implemented, the communication proceeds with h1.
The frontend now sends many concurrent requests (large loop with fetch). Each HTTP request is sent on a dedicated TCP h1 connection. No two concurrent h1 requests can use the same TCP connection, the browser has to wait for the response to come back to send another request on the same connection.
Based on this logic you could flood the server with TCP connections, so chrome and other browsers implemented an h1 connection pool per domain and this limit is hard coded to 6.
So if the frontend sent 6 requests concurrently on 6 connections, all subsequent requests get stalled and queued until a connection is available (a response was received). This leads to performance and latency issue.
Enabling h2 can of course help alleviate this because you essentially are no longer chocked by the h1 pool limit, you would have one TCP connection but create new stream for each request or reuse existing available streams. There is a max stream limit of course as well but its high (I think 250 is the default)
However enabling h2 isn’t free, it comes with an extra cost on the backend, especially that h2 processing is more cpu and memory intensive compared to simple h1 because of the additional h2 frame processing.
So enabling h2 does help sometimes but we need to watch out, does this really mask a problem in the frontend? Did we just band-aid a bug by opening the floodgates, could we have possibly optimized the code to not send so many requests? or lazy load perhaps to apportion them. This is equivalent to running inefficient code and demanding more hardware to make it fast.
Or no! the frontend absolutely need to send so many requests initially and it is definitely more than 6 and we don’t want any stalling so we don’t affect the user experience, later the app calms down and sends only handful. Here it makes sense to enable h2 and won’t necessarily overwhelm the backend.
its tricky and I don’t know if there is always a clear answer, this requires understanding the whole stack and making the right choice.
السلام عليكم ،في خاطري اتكلم عن موضوع وفي كثير بيتجاهل الكلام الي بكتبه ،صراحة انا ماعندي العلم الكافي عشان افتي او اتكلم ولا انا انسانه مثالية لكن الموضوع يقهر بسبب انتشاره وقله الي ينكرونه ويظهر بالتايم بشكل مستمر
"دع المقادير تجري في أعنّتها
ولا تبيتنّ إلا خالي البالِ
ما بين غمضةِ عين وانتباهتها
يغير الله من حال إلى حالِ
فكن مع الناس كالميزانِ معتدلًا
ولا تقولن ذا عمي وذا خالي
العم من كنت مغمورٌ بنعمتهِ
والخال من كنت من أضراره خالِ
لايقطع الرأس إلا من يركبه
ولا ترد المنايا كثرة المال.