Here is my fundamental understanding of the CPU and threads(naive!). The processor can run one thread per core.
System information on my laptop reads as show below
Processor Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz, 2112 Mhz, 4 Core(s), 8 Logical Processor(s)
**Can run 8 threads in parallel **
In order to validate my understanding i create a Spring Boot(embedded tomcat) to handle each request
@GetMapping("/ping")
public String ping(@RequestParam String id) throws InterruptedException {
System.out.println(MessageFormat.format("The request id is {0}", id));
int i = Integer.parseInt(id);
long now = System.currentTimeMillis();
long period = 5000L;
long later = System.currentTimeMillis();
if (i % 2 == 1) {
while (later - now <= period) {
later = System.currentTimeMillis();
}
}
return PING_SUCCESSFUL;
}
I also set the max threads on tomcat to the following
server.tomcat.max-threads=200
I now use Apache JMeter to trigger 200 requests in a duration of 1 seconds
My expectation is my system is constrained to run only 8 threads and hence the total run time of the requests should be at least (200 / 8)*5 = 125 seconds
However even the 125 seconds is not realistic as there are other applications running on my system like Browser, JMeter, IntelliJ which should account for some threads themselves.
I observe a contrasting behavior - the total runtime observed is 5 seconds . How is this possible for the system to run more threads than the limit? ( I find some understanding amiss about the threads and how the underlying processors seem to paralelize the threads)