PoC: two variants of Export and Input managers implementation and compare them

PoC: two variants of Export and Input managers implementation and compare them

Problem statement 

Spring migration process for mod-data-export module assumes removing Vert.x completely. In this case, most of the existing logic that utilizes asynchronous operations needs to be refactored as well. Moreover, current implementation of Input and Export managers uses Vert.x event bus messaging system to communicate to each other, so that alternative must be found. 

Spring allows us to use SpringEvents as a messaging system in two modes: synchronous with one single thread, and asynchronous with multiple threads running in parallel. In this PoC it needs to prove that keeping asynchronous logic is the better approach in terms of efficiency and scalability. 

Approach description 

For this PoC Input and Export managers were simulated using two approaches: single thread and multiple threads. Both utilize Spring Events.  

To simulate communications between Input and Export managers, a specific CSV file with UUIDs was used. InputDataManager reads this file by chunks (chunk size = 50) and invokes ExportManager to export data. In turn, ExportManager creates and initializes Event with the obtained data and publishes Event using ApplicationEventPublisher. Next, InputDataManager listens to events and accepts them writing the event data to the temporary file. 

draw.io Diagram

Experiments 

The number of records to export was up to 8 million. Multithreading approach assumes a specific pool size that can be set to TaskExecutor in SpringEvents. In the experiment sizes 2 through 14 were used. Tests were run for single thread and multiple threads with different pool size. The final result was obtained as the average value after running test 10 times.

 

Number of records to export 

Thread pool size 

Single thread 

2 

4 

6 

8 

10 

12 

14 

10 

1132 

428 

458 

691 

290 

264 

326 

3926 

30 

1011 

3636 

24928 

656 

1107 

1085 

1455 

607 

50 

505 

1226 

417 

882 

234 

226 

280 

773 

80 

1456 

2863 

909 

1550 

745 

736 

756 

1268 

100 

916 

2838 

439 

534 

475 

270 

318 

1121 

300 

3885 

4471 

2162 

3566 

1519 

1678 

1557 

3132 

500 

2522 

3124 

2670 

5927 

2561 

2312 

2243 

3705 

800 

3084 

6436 

3953 

9528 

3997 

3273 

3097 

18150 

1000

10976 

6013 

4423 

8298 

4381 

3905 

3982 

13014 

3000

15533 

11763 

11102 

21141 

9881 

9546 

10369 

19993 

5000

28271 

18575 

17752 

29800 

14826 

14983 

16398 

38065 

8000

39097 

29182 

25816 

36310 

23554 

22975 

60651 

53460 

10000

45717 

35531 

35247 

43573 

29766 

29584 

31388 

64969 

30000

156711 

107034 

102025 

109900 

85908 

82695 

92462 

255216 

50000

231948 

180564 

156861 

209451 

141517 

151151 

154134 

332731 

80000

387508 

272977 

269856 

303386 

265004 

268070 

251783 

590389 

100000

474566 

378202 

330470 

377209 

304966 

299092 

302823 

695058 

300000

1370703 

1082227 

1019661 

1046575 

928820 

924479 

963967 

1936410 

500000

2488023 

1899734 

1720650 

1795224 

1589516 

1542793 

1594362 

4051557 

800000

4260228 

3134739 

3027948 

2928163 

2594847 

2563968 

2652752 

5281513 

1000000

5239160 

4279949 

3940037 

4071383 

3555557 

3376451 

3431366 

6707719 

3000000

18692063 

15069819 

15149831 

15066745 

15311940 

14763811 

15586895 

22560792 

5000000

30921539 

24588493 

23073730 

25115766 

25224996 

23784953 

24254831 

36026209 

8000000

45659512 

36571303 

33788335 

35870766 

34435626 

33772925 

34213309 

56599696 

 

Results

According to the results above, the most efficient way (in terms of elapsed time for export) is to use multithreading approach with pool size > 2.

 

Appendix

Project that was used for testing: project