mountebank icon indicating copy to clipboard operation
mountebank copied to clipboard

Improve mountebank performance by hoisting require calls

Open Havunen opened this issue 3 years ago • 3 comments

This pull request hoists most of the "require" statements out from runtime execution code path to improve the mountebank mock performance.

Calling require goes into NodeJS module resolution process which is error prone, needs disk I/O and so on.

Its good practice to require needed module outside the application module and then just use them runtime.

Performance comparison:

Before ( response times vs load ): 1min 13seconds ( 15000 requests )

summary +      1 in 00:00:00 =    5,4/s Avg:   102 Min:   102 Max:   102 Err:     0 (0,00%) Active: 1 Started: 1 Finished: 0
summary +   5759 in 00:00:29 =  201,5/s Avg:   320 Min:    13 Max:   514 Err:     0 (0,00%) Active: 97 Started: 100 Finished: 3
summary =   5760 in 00:00:29 =  200,2/s Avg:   320 Min:    13 Max:   514 Err:     0 (0,00%)
summary +   6281 in 00:00:30 =  209,3/s Avg:   433 Min:   190 Max:   509 Err:     0 (0,00%) Active: 77 Started: 100 Finished: 23
summary =  12041 in 00:00:59 =  204,9/s Avg:   379 Min:    13 Max:   514 Err:     0 (0,00%)
summary +   2959 in 00:00:14 =  211,7/s Avg:   274 Min:    20 Max:   389 Err:     0 (0,00%) Active: 0 Started: 100 Finished: 100
summary =  15000 in 00:01:13 =  206,2/s Avg:   358 Min:    13 Max:   514 Err:     0 (0,00%)

image

After ( response times vs load ) 24 seconds ( 15000 requests )

summary +   3170 in 00:00:06 =  507,9/s Avg:    23 Min:     4 Max:    93 Err:     0 (0,00%) Active: 20 Started: 32 Finished: 12
summary +  11830 in 00:00:17 =  691,8/s Avg:    35 Min:     3 Max:    70 Err:     0 (0,00%) Active: 0 Started: 100 Finished: 100
summary =  15000 in 00:00:23 =  642,6/s Avg:    32 Min:     3 Max:    93 Err:     0 (0,00%)

image

This benchmark was done using JMeter 5.5 Intel Core i9-11950H ( 16 CPUs ) 32GB RAM

The benchmark test included the mocking logic, so its safe to say performance improvement to mountebank is more than 10X

Havunen avatar Sep 06 '22 09:09 Havunen

This PR fixes: https://github.com/bbyars/mountebank/issues/695

Havunen avatar Sep 06 '22 09:09 Havunen

Hmm, I did run the tests locally, I have no idea why circle CI is failing

Maybe same reason as here: https://github.com/bbyars/mountebank/pull/694

Havunen avatar Sep 06 '22 09:09 Havunen

Thanks. I think CircleCI is failing due to a permissions error on PRs related to the fact that I have to "npm install -g" to downgrade npm to v6, as v8 has a memory leak that fails tests. That should be a short-term hack. I'll take a look as soon as I can. -Brandon

On Tue, Sep 6, 2022 at 4:29 AM Sampo Kivistö @.***> wrote:

Hmm, I did run the tests locally, I have no idea why circle CI is failing

— Reply to this email directly, view it on GitHub https://github.com/bbyars/mountebank/pull/696#issuecomment-1237900666, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAARFP3OK4GRXKK2CMECWU3V44FJLANCNFSM6AAAAAAQFUHR5E . You are receiving this because you are subscribed to this thread.Message ID: @.***>

bbyars avatar Sep 07 '22 15:09 bbyars

merged latest changes from master branch

Havunen avatar Sep 25 '22 08:09 Havunen

@bbyars I opened another PR to update to npm 8 to fix circle ci https://github.com/bbyars/mountebank/pull/701

Havunen avatar Sep 25 '22 11:09 Havunen

I merged latest changes and tests are now passing @bbyars

Havunen avatar Oct 03 '22 05:10 Havunen

This is amazing, thanks so much for all your work. Apologies it took me so long to get to it, life's been a little hectic lately.

bbyars avatar Oct 09 '22 15:10 bbyars