A little experiment to see how we can dynamically calculate pricing with Apache POI + a spreadsheet.
- Current implementation uses a single workbook instance preloaded into memory and protected with
synchronized
- This approach heavily reduces throughput while guaranteeing safety in formula calculation
- Potential optimizations to explore:
- Cloned workbooks in memory to remove usage of
synchronized
- Pool of workbooks so that concurrent threads may use a free workbook, much like socket connections
- Dive deeper into POI's implementation of FormulaEvaluator to see whether there are thread-safe implementations / other ways of getting cells evaluated
- Cloned workbooks in memory to remove usage of
SimpleCalculation.xlsx - Just a simple spreadsheet with 4 values to be summed up.
AdvancedCalculation.xlsx - Advanced spreadsheet that calculates projected revenue of a clinic. With colors, macros, lots of values and formulas - A real scenario of what an actuary will produce.
-
cd api && ./gradlew bootRun
-
Simple case: GET
http://localhost:8080/calculate/simple/780
or any numberhttp://localhost:8080/calculate/simple/{value}
-
Advanced case: GET
http://localhost:8080/calculate/advanced?medicard=0.1&managedCare=0.1&privateInsurance=0.2&selfPay=0.6
-
cd api
-
Install k6
-
Run the simple scenario with 100 concurrent users over 60s -
k6 run loadtest/simple.js --vus 100 --duration 60s
-
Tested on a machine with 6 cores - Got 9-10K rps. Your results may vary. See this PR
Loadtest | Monitor |
---|---|
-
(Optional) to run the advanced scenario -
k6 run loadtest/advanced.js --vus 100 --duration 60s
. This one clocks about 700 rps -
(Optional) to run all scenarios -
k6 run loadtest/index.js --vus 100 --duration 60s