Is it a performance hit that Spring MVC controllers are singleton?

Viewed 35

Given that beans in Spring, including Controllers, have a scope of singleton by default, will it not be a performance hit or delay in servicing requests if multiple requests are made by multiple users?

In a web application with tens of 1000s of active users, who may access the same or different end-points in the same controller, how will their request be handled if there is only one instance of this controller or even service?

Will it not require that each active request is serviced before the controller could handle the next one? Will the users not see too much delay if there are multiple active users making requests?

I know that the controllers and service beans must be stateless (and let's say they completely are stateless) but my question is more to do with how this single instance handles multiple requests without showing any type of delay.

1 Answers

Because the controller has no state, no synchronization is needed. And hence requests can be processed concurrently on the same controller; so no delays.

At a CPU level, the cache line with the controllerd data will be in the SHARED state (MESI), so no cache coherence traffic is needed because every CPU could have that cache line in that state.

Related