Spring boot application slow performance

Viewed 3497

I have a very basic Spring boot application, which exposes CRUD Rest APIs for a very simple entity. Running performance test using JMeter shows the very bad response time

Product (id, name, description)

Constraints: id PK AUTOINCREMENT

Settings:

  • Number of Threads: 100
  • Ramp-up period: 10 (seconds)
  • Infinite loop
  • Duration: 60 (seconds)

Response Graph Summary Report

4 APIs exposed to perform the following functions

@Override
public Product findById(Integer id) {
    return repository.findById(id)
            .map(mapper::map)
            .orElseThrow(() -> new RecordNotFoundException(1, "Product not found"));
}

@Transactional
@Override
public Product create(Product Product) {
    ProductEntity entity = mapper.map(Product);
    
    repository.save(entity);

    return mapper.map(entity);
}

@Transactional
@Override
public Product update(Integer id, Product Product) {
    ProductEntity entity = repository.findById(id).orElseThrow();

    mapper.mapTo(entity, Product);

    repository.save(entity);

    return mapper.map(entity);
}

@Transactional
@Override
public void delete(Integer id) {    
    repository.deleteById(id);
}

I have tried to see the reason with visual VM. It seems repository functions are taking too much time. I assume its the database which is causing the issue.

Connection pool settings: As I have not set anything and assuming my applicaion is using HikariCP and default size is 100.

Database: For above results tried with MySQL (innodb engine) and have disabled autocommit.

Spring Boot version: 2.4.0

System: 16GB RAM, core i7

Question:

Am I right its the connection pooling or database that is the bottleneck here and what will be the optimum value for pool size to reduce the response time?

Why all APIs follow the same trend in the graph - together rise or drop?

Update:

  1. Based on the suggestion hosted all of them on a separate machine (Cloud-based)
  2. Profiled a bit - the repository is taking time (com.sun.proxy.$.methodName)
2 Answers

I can think of the following possible reasons:

  1. The machine where your spring boot application runs lacks resources (CPU, RAM, etc.) - make sure to monitor them using i.e. JMeter PerfMon Plugin
  2. Use a profiler tool like YourKit or JProfiler to see where the application spends the most time
  3. If you think that the problem is in the database:

You can do these to find the problem :

1- Use Gatling for your performance test, it uses the lower resource and doesn't impact your result.

2- Use an APM agent to monitor exactly what is the process that toke long, is database queries, or not(APM)

3- use undertow instead of tomcat or other web applications

Related