java - HttpClient is "reinitialized" after each 100 calls -


i have groovy script has post lot of calls api. using 1 http client calls - for best performance

there code:

httpclient = new httpclient()  def start = new date().gettime() def = 0  (item in items) {   post(item)   def spend = new date().gettime()- start // usual call takes 100-300 miliseconds   start = new date().gettime()    if(spend>1000){   logger.debug   }   ++i }  def post(item){   def httpmethod = new postmethod(endpoint)   httpmethod.setrequestheader(new header("content-type", "application/json"))   httpmethod.setrequestheader(new header("host", aws.host))   httpmethod.setrequestheader(new header("x-amz-date", amzdate))   httpmethod.setrequestheader(new header("authorization", authorizationheader))   def requestentity = new stringrequestentity(item, "application/json", "utf-8")   httpmethod.setrequestentity(requestentity)   def statuscode = httpclient.executemethod(httpmethod)   httpmethod.releaseconnection()   return statuscode >= 200 && statuscode < 300 } 

this code printed me:

debug: 0 : 1504  debug: 100 : 1389 debug: 200 : 1177 debug: 400 : 1200 debug: 500 : 1058 ... 

as correct httpclient initialize during first call , has reinitialize same stuff after each 100th call.

edit: code calls amazon api gateway. when change method , call google - issues wasn't reproduced.

is possible avoid reinitialization?

its not possible avoid re-initialization cost.

api gateway closing connection after 100 requests (it'll return connection: close 1 of response headers). client has re-establish tcp connection , perform full tls handshake.

i api gateway, i'll @ if can this. though, cannot promise anything.

update: should less of issue now. number has been increased 1000.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -