JDBI connector performance anamoly with aws lambda

23 Views Asked by At

I am trying to use AWS lambda with postgres and JDBI as a connector but I see a performance difference in how I query with JDBI

First Way: Using interface

Lambda:

static{
        jdbi = JdbiConnector.getJdbiInstance();
   }

handler{
      List<Configurations> config = jdbi.withExtension(ConfigurationsDao.class, dao ->{
            return dao.getConfigurationByKey(key);
        });
}


Config dao:
public interface ConfigurationsDao {

        @SqlQuery("SELECT * from configuration where key = :key")
        @RegisterBeanMapper(Configurations.class)
        public List<Configurations> getConfigurationByKey(@Bind("key") String key);
}

When cold started , lambda takes approx 5 seconds in total and duting warm start approx 400-500 ms

On the other hand

Second way:

Lambda:

static{
        jdbi = JdbiConnector.getJdbiInstance();
   }

handler{
      List<Configurations> config = new HelperClass().selectUsingJdbi(handle,input.sql);
}


HelperClass{
public List<Configurations> selectUsingJdbi(Handle handle,String val){
        return handle.createQuery("select * from configuration where key = :key").bind("key",val ).mapToBean(Configurations.class).collect(Collectors.toList());
        
    }
}

Here when cold started : lambda takes 2-3 seconds and warm started only 2-3 ms

Can anyone explain this performance gap? Or am i doing anything wrong here

NOTE: Connection part of db is present during cold start, its not counted in duration

Its just that interface way looks more cleaner

0

There are 0 best solutions below