├── src ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── pivotal │ │ └── PerftestApplication.java └── test │ ├── java │ └── pivotal │ │ └── PerftestApplicationTests.java │ └── scala │ └── pivotal │ └── PerformanceSimulation.scala ├── .gitignore ├── README.md └── pom.xml /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /src/test/java/pivotal/PerftestApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pivotal; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class PerftestApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/pivotal/PerformanceSimulation.scala: -------------------------------------------------------------------------------- 1 | package pivotal 2 | 3 | import io.gatling.core.Predef._ 4 | import io.gatling.http.Predef._ 5 | import scala.concurrent.duration._ 6 | 7 | class PerformanceSimulation extends Simulation { 8 | 9 | val httpProtocol = http 10 | .baseURL("http://localhost:8080") 11 | .acceptHeader("text/plain") 12 | .acceptEncodingHeader("gzip, deflate") 13 | .userAgentHeader("Gatling") 14 | 15 | val scn = scenario("PerformanceSimulation") 16 | .repeat(10) { 17 | exec(http("GET /io").get("/io")) 18 | } 19 | 20 | setUp( 21 | scn.inject(atOnceUsers(1000)) 22 | ).protocols(httpProtocol) 23 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple Spring Boot performance testing simulator 2 | 3 | ## Getting Started 4 | 5 | ```shell 6 | $ mvn spring-boot:run 7 | # (in another terminal) 8 | $ mvn gatling:test 9 | $ open target/gatling/performancesimulation-*/index.html 10 | ``` 11 | 12 | ## Observations 13 | 14 | The endpoint `/io` _simulates_ IO by sleeping for an interval between 200 and 700ms. If you see requests taking longer than 700ms to fulfil, then there's a bottleneck somewhere. 15 | 16 | 1. Check `ulimit -n`, the number of file descriptiors your process can have open at a time. Number of file descriptors == number of connections, for both the server and the performance test. 17 | 2. Change `server.tomcat.max-threads` in application.properties. By default Spring Boot uses an embedded Tomcat server, and the default maximum threads if not set is 200. 18 | -------------------------------------------------------------------------------- /src/main/java/pivotal/PerftestApplication.java: -------------------------------------------------------------------------------- 1 | package pivotal; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.context.request.async.DeferredResult; 9 | 10 | import java.util.concurrent.Callable; 11 | 12 | import static java.lang.Math.atan; 13 | import static java.lang.Math.cbrt; 14 | import static java.lang.Math.tan; 15 | 16 | @SpringBootApplication 17 | @RestController 18 | public class PerftestApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(PerftestApplication.class, args); 22 | } 23 | 24 | @GetMapping("/io") 25 | public String io() throws InterruptedException { 26 | long sleepDuration = 200L + (long) (500L * Math.random()); 27 | Thread.sleep(sleepDuration); 28 | return "done after " + sleepDuration + "ms"; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pivotal 7 | perftest 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | perftest 12 | Demoing performance on PCF 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | io.gatling.highcharts 41 | gatling-charts-highcharts 42 | 2.2.5 43 | test 44 | 45 | 46 | 47 | 48 | ${project.name} 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | net.alchim31.maven 56 | scala-maven-plugin 57 | 3.2.1 58 | 59 | 60 | io.gatling 61 | gatling-maven-plugin 62 | 2.2.4 63 | 64 | 65 | 66 | 67 | 68 | 69 | --------------------------------------------------------------------------------