많은 웹 요청 (~ 300000)을하는 스크립트가 있습니다. 이 문제는 각 기능은 비동기 적으로 파일 기술자를 사용하는 각각의 요청, 수천하고 있기 때문에 나는 Too many open files
예외로 실행하는 것입니다이play.api.libs.ws로 요청 일괄 처리
// Setup a new wsClient
val config = new NingAsyncHttpClientConfigBuilder(DefaultWSClientConfig()).build
val builder = new AsyncHttpClientConfig.Builder(config)
val wsClient = new NingWSClient(builder.build)
// Each of these use the wsClient
def getAs: Future[Seq[A]] = { ... }
def getBs: Future[Seq[B]] = { ... }
def getCs: Future[Seq[C]] = { ... }
def getDs: Future[Seq[D]] = { ... }
(for {
as <- getAs
bs <- getBs
cs <- getCs
ds <- getDs
} yield (as, bs, cs, ds)).map(tuple => println("done"))
같이 보입니다.
나는 각자가 자신의 클라이언트를 배치 할 것이다 그래야 내 기능을 다시 정리 시도 :
def getAs: Future[Seq[A]] = {
someCollection.group(1000).map(batch => {
val client = new NingWSClient(builder.build) // Make a new client for every batch
Future.sequence(batch.map(thing => {
wsClient.url(...).map(...)
})).map(things => {
wsClient.close // Close the client
things
})
})
}
그러나이 조기 종료하려면를위한 이해의 원인 (오류 메시지 또는 예외없이) :
(for {
as <- getAs
bs <- getBs // This doesn't happen
cs <- getCs // Or any of the following ones
ds <- getDs
} yield (as, bs, cs, ds)).map(tuple => println("done"))
난 그냥 너무 많은 파일 디스크립터를 열지 않고도 HTTP 요청의 큰 숫자를 만들 수있는 올바른 방법을 찾고 있어요.