Sitemap
Randika Piyathissa

Randika Piyathissa

My journey has been focused on building creative software solutions while collaborating with diverse teams to solve complex technical problems. ๐Ÿš€๐Ÿ“š๐Ÿ’ก

4 min readNov 3, 2024

--

๐˜ผ๐™จ๐™จ๐™š๐™จ๐™จ๐™ž๐™ฃ๐™œ ๐™Ž๐™ฅ๐™ง๐™ž๐™ฃ๐™œ ๐˜ฝ๐™ค๐™ค๐™ฉโ€™๐™จ ๐˜พ๐™–๐™ฅ๐™–๐™˜๐™ž๐™ฉ๐™ฎ ๐™›๐™ค๐™ง ๐˜พ๐™ค๐™ฃ๐™˜๐™ช๐™ง๐™ง๐™š๐™ฃ๐™ฉ ๐™๐™š๐™ฆ๐™ช๐™š๐™จ๐™ฉ ๐™ƒ๐™–๐™ฃ๐™™๐™ก๐™ž๐™ฃ๐™œ โš™๏ธ๐Ÿ“Š

Press enter or click to view image in full size

๐’๐ฉ๐ซ๐ข๐ง๐  ๐๐จ๐จ๐ญ: ๐‡๐จ๐ฐ ๐Œ๐š๐ง๐ฒ ๐‘๐ž๐ช๐ฎ๐ž๐ฌ๐ญ๐ฌ ๐‚๐š๐ง ๐ˆ๐ญ ๐‡๐š๐ง๐๐ฅ๐ž ๐š๐ญ ๐Ž๐ง๐œ๐ž?

Spring Boot has become an essential tool for Java developers, known for simplifying application development with its robust, user-friendly framework. Unsurprisingly, related interview questions about Spring Boot frequently focus on its performance and scalability.

Today, weโ€™ll tackle one such question: How many requests can Spring Boot handle simultaneously?

To clarify, the number of simultaneous requests a Spring Boot application can handle isnโ€™t solely determined by Spring Boot itself but by the embedded web server it uses. Since the embedded web server defines this behavior, understanding how each option manages concurrent requests will provide the best answer.

๐Ÿญ.๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ ๐—ง๐—ผ๐—ฝ ๐—ง๐—ต๐—ฟ๐—ฒ๐—ฒ ๐—ช๐—ฒ๐—ฏ ๐—–๐—ผ๐—ป๐˜๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฟ๐˜€

Spring Boot applications can be configured to run with various embedded web servers, each with distinct advantages. The three main choices are Tomcat, Undertow, and Jetty.

๐Ÿญ. ๐—ง๐—ผ๐—บ๐—ฐ๐—ฎ๐˜

As the default embedded server for Spring Boot, Tomcat is a widely used open-source Servlet container from the Apache Software Foundation. It fully implements the Java Servlet and JavaServer Pages (JSP) specifications, supporting robust enterprise-level features like SSL, connection pooling, and more. This maturity and stability make it ideal for large, complex applications.

However, Tomcatโ€™s comprehensive feature set makes it somewhat heavier compared to other lightweight servers, which can impact memory usage.

๐Ÿฎ. ๐—จ๐—ป๐—ฑ๐—ฒ๐—ฟ๐˜๐—ผ๐˜„

Developed by Red Hat, Undertow is known for its high performance, low memory usage, and modular design, making it a strong choice for handling high-concurrency applications with short connections, such as RESTful APIs. Itโ€™s also the default container for the WildFly application server.

Undertow excels in modern web standards, supporting Servlet 3.1, WebSocket, non-blocking I/O (NIO), and HTTP/2. Its lightweight architecture and modularity make it highly suitable for microservices and cloud-native applications.

๐Ÿฏ. ๐—๐—ฒ๐˜๐˜๐˜†

Jetty, an open-source web server maintained by the Eclipse Foundation, is lightweight and designed with embeddability in mind. This makes it ideal for lightweight applications, development phases, and test environments.

With NIO support, Jetty performs well in handling concurrent connections and is frequently used in continuous integration and DevOps contexts due to its flexible, customizable architecture.

Press enter or click to view image in full size
Modern Technology

๐Ÿ. ๐‚๐จ๐ง๐Ÿ๐ข๐ ๐ฎ๐ซ๐ข๐ง๐  ๐Œ๐š๐ฑ๐ข๐ฆ๐ฎ๐ฆ ๐‚๐จ๐ง๐ง๐ž๐œ๐ญ๐ข๐จ๐ง๐ฌ ๐š๐ง๐ ๐๐ฎ๐ž๐ฎ๐ž ๐‚๐š๐ฉ๐š๐œ๐ข๐ญ๐ฒ

Get Randika Piyathissaโ€™s stories inย yourย inbox

Join Medium for free to get updates fromย thisย writer.

In Spring Boot, using Tomcat as the default embedded server, the capacity to handle simultaneous requests is set through specific configurations in the spring-configuration-metadata.json file. For example, parameters like maxConnections (the maximum number of concurrent connections) and acceptCount (the maximum number of requests that can wait in the queue when all threads are busy) can be adjusted to manage request handling limits effectively.

Press enter or click to view image in full size

To locate Tomcatโ€™s maximum connection setting, open the configuration file and search for server.tomcat.max-connections. This parameter defines the highest number of connections Tomcat will accept simultaneously.

Press enter or click to view image in full size

By default, Tomcat is configured to handle up to 8,192 simultaneous connections (8 * 1,024). At first glance, it might seem that this would allow Spring Boot to manage 8,192 requests at once. However, this isnโ€™t entirely accurate.

While Tomcat does permit up to 8,192 connections, it also has a queue capacity for handling requests once the connection limit is reached. This means that the actual number of requests Spring Boot can handle simultaneously is the sum of Tomcatโ€™s maximum connections and its maximum waiting queue size.

To configure this queue capacity, search for the parameter server.tomcat.accept-count in the spring-configuration-metadata.json file, which sets the maximum number of requests that can wait when all connections are in use.

Press enter or click to view image in full size

๐Ÿ‘. ๐‡๐š๐ง๐๐ฅ๐ข๐ง๐  ๐‚๐จ๐ง๐œ๐ฎ๐ซ๐ซ๐ž๐ง๐ญ ๐‘๐ž๐ช๐ฎ๐ž๐ฌ๐ญ๐ฌ

In summary, the default capacity for handling simultaneous requests in Spring Boot equals Tomcatโ€™s maximum connections (8,192) plus the maximum queue size (100), totaling 8,292 requests.

These values are customizable within Spring Bootโ€™s configuration settings, allowing developers to adjust the maximum connection and queue capacities as needed. Hereโ€™s an example of how to modify these configurations:

Press enter or click to view image in full size

๐Ÿ’. ๐€๐๐๐ข๐ญ๐ข๐จ๐ง๐š๐ฅ ๐“๐ข๐ฉ: ๐‚๐จ๐ง๐Ÿ๐ข๐ ๐ฎ๐ซ๐ข๐ง๐  ๐ญ๐ก๐ž ๐–๐ž๐› ๐‚๐จ๐ง๐ญ๐š๐ข๐ง๐ž๐ซ

Wondering how to switch the web container to Jetty or Undertow in Spring Boot? Hereโ€™s how you can do it.

๐Ÿ’.๐Ÿ ๐’๐ฐ๐ข๐ญ๐œ๐ก๐ข๐ง๐  ๐ญ๐จ ๐‰๐ž๐ญ๐ญ๐ฒ

To set Jetty as the web container in Spring Boot, simply update the pom.xml file as shown below:

Press enter or click to view image in full size

In other words, simply exclude the default Tomcat and add the Jetty dependency.

--

--

Randika Piyathissa
Randika Piyathissa

Written by Randika Piyathissa

My journey has been focused on building creative software solutions while collaborating with diverse teams to solve complex technical problems. ๐Ÿš€๐Ÿ“š๐Ÿ’ก