Devoxx Invoice Generator V2
Based on the community feedback I decided to redevelop the Devoxx Invoice Generator application using "pure" JDBC and DB Generator instead of JPA with Java logic to increment the invoice number.
We start by injecting the DataSource which uses HikariDataSource underneath. This is important when discussing the stats anomaly later on.
The getInvoiceNumber is where the "magic" happens. Here we get the next available invoice number from the Database Sequence generator. I've included the actual SQL statement as a comment above the code.
Liquibase config
The related Liquibase config looks as follows:
When running 'siege' for the first time (cold) on this implementation
?siege -c200 -t10s --content-type "application/json" 'https://localhost:8080/api/invoice/99 POST "invoice_generation"'?
we get the following results
However if I run siege a second time on the same running server the results are much higher. Cold Vs Hot server probably related to the underlying datasource "filling up" ?
领英推荐
Because of these results I re-run the JPA siege stats with a cold and hot server and compared them with the JDBC results.
As you can see the JDBC and DB Sequencer results are still A LOT FASTER !!
So with 600 tx/s I think we're ready to welcome our Devoxxians to ALF.IO registration. Now lets hope that the Kubernetes setup is stable and fast enough to handle the registration burst we'll get on August 16th at 9am CEST ??
Comments and suggestions are always welcome!
Stephan
Addendum : DB Sequence Cache
It was brought to my attention that PostgreSQL has a cache option for the CREATE SEQUENCE query.
The optional clause?CACHE?cache?specifies how many sequence numbers are to be preallocated and stored in memory for faster access. The minimum value is 1 (only one value can be generated at a time, i.e., no cache), and this is also the default.
Strangely enough adding a sequence with a cache of 2000 had no impact on the performance!? #SuggestionsWelcome
It has also been brought to my attention that using Spring JdbcTemplate (a level of abstraction) instead of "pure"Java. It would reduce the code complexity (approx 50% less code) but maybe a marginal performance hit.
Software Craftsman | Distributed Platforms Architect | Mentorship | Java
1 年That's awesome! I've been using jdbc for a while exactly because of some performance issues too! I don't know if I lost something, but why do you need to use a sequence? Wouldn't an auto increment column work in this case?