java - Apache HTTP Client: build simulator using multithreaded environment -


i building standalone java application generate load on system, simulating real world conditions.

the application multithreaded, using concurrent framework generate lots of pooled threads, each of runs "sessions". when session complete, runnable ends , thread returned scheduler pool. each "session" consists of following:

  • generate http put #1 server
  • wait x seconds (randomized within logical limit)
  • generate http put #2 server
  • generate http put #3 server
  • wait y seconds (randomized within logical limit)
  • generate http put #4 server
  • generate http put #5 server

approximately 2 minutes taken per session

each thread created concurrent pool maintains connection (an httpclient) reused subsequent sessions. after each request call httprequest.releaseconnection() made, recommended.

it works pretty well. perhaps well.

while keeping connections open , releasing them gives optimum performance, since building simulator don't want optimal performance. want simulate suboptimal performance. want server have go through connection establishment on each session.
want create connection (embedded in http client) @ beginning of each session , close @ end of session.

to accomplish this, close httpclient @ end of session , set variable null (both in clause). when application session thread starts new session, if client null, builds new 1 using httpclientbuilder. however, when that, sorts of connection pool errors foul simulation.

is there right way make connections suboptimally, described above, apache httpclient? kind of crazy question, real one.

you can toggle re-use of connections within pool using builder's setconnectionreusestrategy. defaultconnectionreusestrategy re-use connections whenever possible, noconnectionreusestrategy close connections returned pool.

i used these connection re-use strategies in reverse: in production no re-use set (to ensure proper load-balancing - every new connection directed healthy server), during testing had switch default re-use strategy since test creating many connections test-machine ran out of ports use (after local port used os keeps port in waiting/cooldown room, part of tcp protocol). thing test-code defers production code 1 setting of connection re-use strategy.

note combination of connection pool , no re-use of connections still has purpose: pool prevent more it's maximum allowed size of open connections. e.g. if application decides wants open 100 connections @ same time, , pool has maximum size of 30, pool let other requests other 70 connections wait until connections returned. way make clients behave nice , prevent them overloading server.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -