Tôi đã cố gắng các POC sau để kiểm tra như thế nào để có được đồng thời caoLàm thế nào để đạt được đồng thời cao với spray.io trong ví dụ Tương lai và Thread.sleep này?
implicit def executionContext = context.system.dispatchers.lookup("async-futures-dispatcher")
implicit val timeout = 10 seconds
val contestroute = "/contestroute" {
get {
respondWithMediaType(`application/json`) {
dynamic {
onSuccess(
Future {
val start = System.currentTimeMillis()
// np here should be dealt by 200 threads defined below, so why
// overall time takes so long? why doesn't it really utilize all
// threads I have given to it? how to update the code so it
// utilizes the 200 threads?
Thread.sleep(5000)
val status = s"timediff ${System.currentTimeMillis() - start}ms ${Thread.currentThread().getName}"
status
}) { time =>
complete(s"status: $time")
}
}
}
}
}
cấu hình của tôi:
async-futures-dispatcher {
# Dispatcher is the name of the event-based dispatcher
type = Dispatcher
# What kind of ExecutionService to use
executor = "thread-pool-executor"
# Configuration for the thread pool
thread-pool-executor {
# minimum number of threads to cap factor-based core number to
core-pool-size-min = 200
# No of core threads ... ceil(available processors * factor)
core-pool-size-factor = 20.0
# maximum number of threads to cap factor-based number to
core-pool-size-max = 200
}
# Throughput defines the maximum number of messages to be
# processed per actor before the thread jumps to the next actor.
# Set to 1 for as fair as possible.
throughput = 100
}
tuy nhiên
khi tôi chạy băng ghế dự bị apache như thế này:
ab -n 200 -c 50 http://LAP:8080/contestroute
Kết quả tôi nhận được:
Server Software: Apache-Coyote/1.1
Server Port:erred: 37500 bytes
HTML transferred: 10350 bytes
Requests per second: 4.31 [#/sec] (mean)
Time per request: 34776.278 [ms] (mean)
Time per request: 231.842 [ms] (mean, across all concurrent requests)
Transfer rate: 1.05 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 5 406 1021.3 7 3001
Processing: 30132 30466 390.8 30308 31231
Waiting: 30131 30464 391.8 30306 31231
Total: 30140 30872 998.9 30353 33228 8080
Document Path: /contestroute
Document Length: 69 bytes
Concurrency Level: 150
Time taken for tests: 34.776 seconds
Complete requests: 150
Failed requests: 0
Write errors: 0
Non-2xx responses: 150
Total transferred: 37500 bytes
HTML transferred: 10350 bytes
Requests per second: 4.31 [#/sec] (mean)
Time per request: 34776.278 [ms] (mean)
Time per request: 231.842 [ms] (mean, across all concurrent requests)
Transfer rate: 1.05 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 5 406 1021.3 7 3001
Processing: 30132 30466 390.8 30308 31231
Waiting: 30131 30464 391.8 30306 31231
Total: 30140 30872 998.9 30353 33228
Tôi có thiếu thứ gì đó lớn không? Tôi cần phải thay đổi gì để có các số spray
và futures
sử dụng tất cả các chủ đề mà tôi đã cung cấp cho nó?
(để thêm tôi đang chạy trên đầu trang của tomcat servlet 3.0)
tôi biết đó là mã ví dụ, nhưng tại sao 'ngủ' bên trong mã đang thực thi dưới dạng' Tương lai'. Bằng cách đó bạn về cơ bản là lấy chủ đề đang chạy mà Tương lai ra khỏi hoa hồng trong 5 giây và nó không thể được giao cho một diễn viên/tương lai ở tất cả trong 5 giây đó. – cmbaxter
Tôi đang mô phỏng một hoạt động chạy dài, vì vậy tôi có thể xem liệu tôi có thể sử dụng 200 luồng để chạy thao tác chạy dài này không. – Jas
Bạn có chắc chắn rằng hệ thống diễn viên cơ bản cho phun không phải là cũng chọn lên bối cảnh thực thi 'async-futures-dispatcher'. Nếu nó vô tình nhặt nó lên (vì nó được định nghĩa là ẩn) thì đó có thể là một phần của vấn đề. Đó là một ý tưởng tốt để tường lửa chặn mã vào một ngữ cảnh thực thi riêng biệt từ điều phối viên chính akka như bạn đã làm ở đây, nhưng nó sẽ không phục vụ mục đích của nó nếu akka cũng đang sử dụng ngữ cảnh thực thi này để chạy các tác nhân đại diện cho tuyến đường này. – cmbaxter