นักแสดงเริ่ม BufferOverflowException ตอนที่กำลังส่งเดียว

0

คำถาม

ฉันกำลังพยายามส่งสองสามร้อยร้องขอ http จาก akka นักแสดงแต่ฉันกำลังจะ

akka.stream.BufferOverflowException: Exceeded configured max-open-requests value of [16]. This means that the request queue of this pool (HostConnectionPoolSetup(places.api.here.com,443,ConnectionPoolSetup(ConnectionPoolSettings(16,1,5,16,1,Duration.Inf,100 milliseconds,2 minutes,30 seconds,ClientConnectionSettings(Some(User-Agent: akka-http/10.2.0)...

นี่การทำงานของโปรแกรมconf

   http {
          host-connection-pool {
            max-connections = 16
            min-connections = 1
            max-open-requests = 16
          }
        }

นี่รหัส

override def receive: Receive = {
      case Foo(_) => 
       val res: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = "http://..."))
   // do something for the result

ฉันพยายามจะควบคุมโดยรัฐ e.g

override def receive: Receive = run(0)
def run(openRequests: Int) : Receive = {
  case Foo(_) if openRequests <= 16 => 
     context.become(run(openRequests + 1))
       val responseFuture: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = "http://..."))
       responseFuture.foreach(context.become(run(openRequests - 1)))
        //...

ยังไงฉันก็เหมือนกันข้อยกเว้นของ BufferOverflowException

คำแนะนำบางอย่างจะ greatly รู้สึกขอบคุณ

akka akka-http akka-stream scala
2021-10-22 05:31:19
1

คำตอบที่ดีที่สุด

2

ใช้ context asynchronously ภายใน Future นี่เป็นความคิดที่แย่เหมือนกัน context มันเป็นเพียงใช้งานระหว่างเรียกเพื่อนนักแสดง

เครื่องส่งคืนนั้น context.become(run(openRequests - 1)) ใช้ค่าของ openRequests ตรงเวลา Future คือสร้างขึ้นไม่ใช่ค่าเมื่อมันคือโทรมา ดังนั้นเมื่อคนแรกการร้องขอ completes มันจะเรียก context.become(run(-1)) (ซึ่งมันเห็นได้ชัดว่าจอมปลอม)ถึงแม้ว่ามันอาจจะ 15 การร้องขอไป

ทางออกเป็นเพื่อส่งข้อความส่วนตัวกับตัวเองใน foreach มากกว่าโทรมา context.become โดยตรง ตอนที่นักแสดงแถบประข้อความมัน decrements ค นปัจจุบัน การร้องขอนับและส่งคนใหม่ขอถ้าจำเป็น

2021-10-22 07:52:58

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................