scala - How timeout works in Dispatch -
at api there is:
val http = http.configure(_ .setconnectiontimeoutinms(1) )
what config? use with:
.setmaxrequestretry(0)
i fought failed future after timeout. future create that:
val f = http(u ok as.string) f.map { notificationclientconnectionparams.parsefromstring }
but instead of failure success long after timeout. how should work?
my test looks this:
val starttime = java.time.localtime.now() val f = tcputil2.registerclientviadispatch(clientheaders("12345", "123456789")) f onsuccess { case c => println(s"success: $c") println(java.time.duration.between(starttime, java.time.localtime.now()).tomillis) } f onfailure { case e => println(s"failure:${e.getmessage}") } thread.sleep(2000)
response time in hundreds of milliseconds , got success. bug of dispatch?
an http roundtrip goes through several phases (overly simplified):
- establishing connection
- connection established
- sending request payload
- request payload sent
- waiting response payload
- receiving response payload
- response payload received
from understand measure time between states 1 , 7.
setconnectiontimeoutinms
comes async-http-client used dispatch internally. here's excerpt its documentation:
set maximum time in millisecond
asynchttpclient
can wait when connecting remote host
thus, method sets maximum time client wait between states 1 , 2.
there's setrequesttimeoutinms
:
set maximum time in millisecond asynchttpclient wait response
this method seems set time between states 5 , 6 (or 7, i'm not sure one).
so here's what's happening in case. connect remote host, server accepts connection (the time between 1 , 2 small), future
doesn't failed. there several options: either server takes lot of time prepare response before starts sending (the time between 5 , 6), or response big takes lot of time deliver (the time between 6 , 7), or both. since don't set request timeout, future
not getting failed because of this.
Comments
Post a Comment