@backstreetbrogrammer
--------------------------------------------------------------------------------
Chapter 02 - Virtual Threads - TCP Socket Client-Server code demo
--------------------------------------------------------------------------------
The scalability of server applications is governed by Little's Law, which relates latency, concurrency, and throughput:
For a given request-processing duration (i.e., latency), the number of requests an application handles at the same time (i.e., concurrency) must grow in proportion to the rate of arrival (i.e., throughput).
For example, suppose an application with an average latency of 50ms achieves a throughput of 200 requests per second by processing 10 requests concurrently.
1 request takes 50 ms
2 requests takes 50*2=100 ms
20 requests takes 50*20=1000 ms or 1 second
Thus, to increase throughput from 20 requests per second to 200 requests per second, we need to process 10 requests concurrently.
In order for that application to scale to a throughput of 2000 requests per second, it will need to process 100 requests concurrently.
If each request is handled in a thread for the request's duration then, for the application to keep up, the number of threads must grow as throughput grows.
Unfortunately, the number of available threads is limited because the JDK implements threads as wrappers around operating system (OS) threads.
OS threads are costly, so we cannot have too many of them, which makes the implementation ill-suited to the thread-per-request style.
If each request consumes a thread, and thus an OS thread, for its duration, then the number of threads often becomes the limiting factor long before other resources, such as CPU or network connections, are exhausted.
The JDK's current implementation of threads caps the application's throughput to a level well below what the hardware can support.
This happens even when threads are pooled, since pooling helps avoid the high cost of starting a new thread but does not increase the total number of threads.
Github: github.com/backstreetbrogramm...
- Upgrade to Java 21 Playlist: • Upgrade to Java 21
- Apache Spark for Java Developers Playlist: • Apache Spark for Java ...
- Top Java Coding Interview Problems Playlist: • Top Java Coding Interv...
- Java Serialization Playlist: • Java Serialization
- Dynamic Programming Playlist: • Dynamic Programming
#java #javadevelopers #javaprogramming
Негізгі бет Ғылым және технология 07 - TCP Socket Client-Server code demo
Пікірлер: 2