Re: akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://simple-spray-client/user/IO-HTTP#10

3,582 views
Skip to first unread message
Message has been deleted

Rimeh BN

unread,
Oct 29, 2015, 6:36:51 AM10/29/15
to spray.io User List

I have this error:  akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://simple-spray-client/user/IO-HTTP#-1906143070]] after [60000 ms]

I have this 3 class: the first is Pages:

import akka.actor.ActorSystem

object Pages extends App {

implicit val system: ActorSystem = ActorSystem("simple-spray-client")
def function(n: Int, system: ActorSystem): Unit = {

if (n <= 245) {
new Id(n, system)
val t = n + 1
function(t, system)
}
else {
println("finish")
}
}
function(0, system)


}



the second is: Id
import spray.http.HttpResponse
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{Future}
import scala.util.{Success, Failure}
import akka.actor.ActorSystem
import akka.event.{LoggingAdapter, Logging}
import spray.client.pipelining._
import argonaut._, Argonaut._

class Id (i :Int, systemId: ActorSystem){

case class NameId(name: String, id: Int)
implicit def NameCodecJson: CodecJson[NameId] = casecodec2(NameId.apply, NameId.unapply)("name", "id")

implicit val system: ActorSystem = systemId

val log: LoggingAdapter = Logging(system, getClass)

val pipeline: SendReceive = sendReceive

val responseFuture: Future[HttpResponse] = pipeline {
Get("https://api.guildwars2.com/v2/items?page="+ i+"&page_size=200")
}
responseFuture.onComplete {
case Success(result: HttpResponse) => {
val res: String = result.entity.asString
if (res.contains("Bolt of Damask")) {
val list = res.decodeOption[List[NameId]].get.filter(x => x.name =="Bolt of Damask").head.id
new BuysSells(list, system )
}
}
case Failure(error) =>
log.error(error, "!")
}
}

the third is: BUysSells:
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Success, Failure}
import scala.concurrent.duration._
import akka.actor.ActorSystem
import akka.pattern.ask
import akka.event.Logging
import akka.io.IO
import spray.can.Http
import spray.client.pipelining._
import spray.util._
import argonaut._, Argonaut._

class BuysSells(id: Int, systemid: ActorSystem ){
case class Buys (quantity: Int, unit_price: Int)
case class Sells(quantity: Int, unit_price: Int)
case class CommercePrice(id: Int, whiteList: Boolean, buys: Buys, sells: Sells)

implicit def BuysCodecJson: CodecJson[Buys] =casecodec2(Buys.apply, Buys.unapply)("quantity", "unit_price")
implicit def SellsCodecJson: CodecJson[Sells]= casecodec2(Sells.apply, Sells.unapply)("quantity", "unit_price")
implicit def CommercePriceCodecJson: CodecJson[CommercePrice]= casecodec4(CommercePrice.apply, CommercePrice.unapply)("id", "whitelisted", "buys", "sells")

implicit val system: ActorSystem =systemid

val log = Logging(system, getClass)

val pipeline= sendReceive
val responseFuture= pipeline{
Get("https://api.guildwars2.com/v2/commerce/prices/"+id)
}
responseFuture.onComplete{
case Success(result)=> {
val content = result.entity.asString
val res: CommercePrice = content.decodeOption[CommercePrice].get
log.info(" Sell and buy : {} {}", res.buys, res.sells)
shutdown()
}

case Failure(error) =>
log.error(error, "Couldn't get elevation")
shutdown()
}
def shutdown(): Unit = {
IO(Http).ask(Http.CloseAll)(1.second).await
system.shutdown()
}
}

thanks.

Johannes Rudolph

unread,
Oct 29, 2015, 10:31:22 AM10/29/15
to spray...@googlegroups.com
Hi,

the this is probably the timeout which is automatically applied when
you use `sendReceive` (see [1]). It means that the pipeline has not
been able to get a response for a request during 60 seconds.

This may either mean that the service you connected to didn't answer
in time, or, since you are using the global `sendReceive`, that you
have too many requests scheduled to one host at the same time. That's
because, the global `sendReceive` (i.e. is the sendReceive that is
backed by the request-level API as explained at [2]) is backed by a
pool of HTTP connections that opens only a limited number of
concurrent HTTP connections per host, so that only this number of
requests will be in-flight to one host at each point in time. If you
start more requests than this number (the pool size per host is
governed by the `spray.can.host-connector.max-connections` setting
[3]) requests will start to pile up in an internal queue and may be
serviced too late so that the timeout triggers.

You can change the timeout by defining an implicit timeout value like this:

implicit val sendReceiveTimeout = akka.util.Timeout(4.minutes)
val pipeline: SendReceive = sendReceive // should pick up the timeout implicitly

HTH
Johannes

[1] https://github.com/spray/spray/blob/master/spray-client/src/main/scala/spray/client/pipelining.scala#L34
[2] http://spray.io/documentation/1.2.2/spray-client/
[3] https://github.com/spray/spray/blob/master/spray-can/src/main/resources/reference.conf#L285
> --
> You received this message because you are subscribed to the Google Groups
> "spray.io User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to spray-user+...@googlegroups.com.
> Visit this group at http://groups.google.com/group/spray-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/spray-user/2d2c3b29-2b16-49c1-82d7-26ce721a9178%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Reply all
Reply to author
Forward
0 new messages