Saturday, February 18, 2012

Number of connections on web server in last 1 minute.



Write a data structure to count number of connections on web server in last 1 minute.

Approach:
Use a circular array of size say 60 with cumulative connections stored in indices. 
To calculate how many connections are on web server in last minute, just take difference between the current index and the previous one.
At any point, suppose you are storing the connections at index i, then reset i+1 to 0. 



Code output:

Server Connections in last 1 min: 3
3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Server Connections in last 1 min: 2500473
4042037 8366214 12750825 17069356 21435609 25818813 30193316 34585084 38981930 43362517 47729398 51954656 56319336 60718454 65115406 69495682 73891294 78291081 82663083 85163556 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

Server Connections in last 1 min: 1673643
4042037 8366214 12750825 17069356 21435609 25818813 30193316 34585084 38981930 43362517 47729398 51954656 56319336 60718454 65115406 69495682 73891294 78291081 82663083 86993284 91375051 95752355 100071358 104330554 108415170 112538285 116863280 121258700 125587403 129942011 134230253 138600661 142938928 147332572 151699763 156056115 160386707 164517422 168667052 170340695 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

Server Connections in last 1 min: 1937344
0 8366214 12750825 17069356 21435609 25818813 30193316 34585084 38981930 43362517 47729398 51954656 56319336 60718454 65115406 69495682 73891294 78291081 82663083 86993284 91375051 95752355 100071358 104330554 108415170 112538285 116863280 121258700 125587403 129942011 134230253 138600661 142938928 147332572 151699763 156056115 160386707 164517422 168667052 172844039 177046285 181257855 185477645 189761265 193999235 198216330 202498034 206710346 210913720 215265043 219554608 223756476 228036400 232286104 236596081 240862590 245114846 249370034 253580282 255517626 

Server Connections in last 1 min: 1165884
261960600 266156936 270515554 274897599 279280497 283664192 288055183 292439077 296814993 301208147 305548693 309453194 313561569 317817387 322058006 326376381 330750504 335138909 339517887 340683771 0 95752355 100071358 104330554 108415170 112538285 116863280 121258700 125587403 129942011 134230253 138600661 142938928 147332572 151699763 156056115 160386707 164517422 168667052 172844039 177046285 181257855 185477645 189761265 193999235 198216330 202498034 206710346 210913720 215265043 219554608 223756476 228036400 232286104 236596081 240862590 245114846 249370034 253580282 257793064 

Server Connections in last 1 min: 3375382
261960600 266156936 270515554 274897599 279280497 283664192 288055183 292439077 296814993 301208147 305548693 309453194 313561569 317817387 322058006 326376381 330750504 335138909 339517887 343893181 348271766 352634531 356957672 361256457 365595987 369933329 374262314 378625770 382977564 387371854 391741255 396148986 400533862 404908812 409300391 413695463 418093979 422477882 425853264 0 177046285 181257855 185477645 189761265 193999235 198216330 202498034 206710346 210913720 215265043 219554608 223756476 228036400 232286104 236596081 240862590 245114846 249370034 253580282 257793064 

Server Connections in last 1 min: 902289
261960600 266156936 270515554 274897599 279280497 283664192 288055183 292439077 296814993 301208147 305548693 309453194 313561569 317817387 322058006 326376381 330750504 335138909 339517887 343893181 348271766 352634531 356957672 361256457 365595987 369933329 374262314 378625770 382977564 387371854 391741255 396148986 400533862 404908812 409300391 413695463 418093979 422477882 426851222 431242526 435636157 440017329 444408215 448769117 453168222 457561690 461906594 466303078 470703003 475091017 479476932 483871156 488262033 492585214 496985526 501373444 505753642 510117476 511019765 0 

Server Connections in last 1 min: 2864165
523295700 527683139 532078847 536464008 540855095 545243156 549635094 554029949 558416866 562810843 567209609 571430001 575788814 580182347 584562119 588946702 593321752 596185917 0 343893181 348271766 352634531 356957672 361256457 365595987 369933329 374262314 378625770 382977564 387371854 391741255 396148986 400533862 404908812 409300391 413695463 418093979 422477882 426851222 431242526 435636157 440017329 444408215 448769117 453168222 457561690 461906594 466303078 470703003 475091017 479476932 483871156 488262033 492585214 496985526 501373444 505753642 510117476 514504603 518899160 

1 comment:

  1. are you storing connections info per second or per minute in each bucket ?

    ReplyDelete