1. 程式人生 > >《Http Client 官方文件》7. 高階主題

《Http Client 官方文件》7. 高階主題

7.3.5. 資料

FutureRequestExecutionService通常用於進行大量Web服務呼叫的應用程式中。 為了方便監控或配置調整等,FutureRequestExecutionService會追蹤多項資料。

每個HttpRequestFutureTask提供了獲取任務排程,啟動和結束時間的方法。 此外,請求和任務持續時間也可用。這些資料標準在FutureRequestExecutionService中的FutureRequestExecutionMetrics例項中聚合,可通過FutureRequestExecutionService.metrics()訪問。

task.scheduledTime() // returns the timestamp the task was scheduled
task.startedTime() // returns the timestamp when the task was started
task.endedTime() // returns the timestamp when the task was done executing
task.requestDuration // returns the duration of the http request
task.taskDuration // returns the duration of the task from the moment it was scheduled

FutureRequestExecutionMetrics metrics = futureRequestExecutionService.metrics()
metrics.getActiveConnectionCount() // currently active connections
metrics.getScheduledConnectionCount(); // currently scheduled connections
metrics.getSuccessfulConnectionCount(); // total number of successful requests
metrics.getSuccessfulConnectionAverageDuration(); // average request duration
metrics.getFailedConnectionCount(); // total number of failed tasks
metrics.getFailedConnectionAverageDuration(); // average duration of failed tasks
metrics.getTaskCount(); // total number of tasks scheduled
metrics.getRequestCount(); // total number of requests
metrics.getRequestAverageDuration(); // average request duration
metrics.getTaskAverageDuration(); // average task duration