我正在为特定的SOAP API编写客户端.我的执行时间很长,因此联系了API所有者,他告诉我:
The average duration calls of GetPrices calls calculated from two
sources which store the duration of the calls show a average duration
throughout the 5 days that punter was calling our system of just over
25 millseconds which matches the average of most punters during the
same time period . The two sources are the Sentry Logs which
calculates the duration of the calls between all the application
components and the Time taken from the IISLogs which includes the
transport time from our API server to the punters calling machine .
对于相同GetPrices调用的完全相同的5天,我平均为0.08-0.1s,这比服务器日志显示的长4倍.
可能是我的测量和API所有者测量之间存在如此高差异的原因是什么?
我测量执行时间的方式非常简单:
start_time = time.time()
# GetPrices call
end_time = time.time() - start_time
如果我能提供任何其他信息,请告诉我.
解决方法:
请考虑下表.
简而言之,您正在考虑服务器工作负载,服务器不应该.
client server
start timing
client get (small data) -> server receive request
<- server ack request start timing
client receive ack
client waiting response server workload to create response
<- server response (big data)
client receive response
client ack response -> server stop timing
client workload parsing response
client stop timing
如果您能够在ack点开始/停止计时,则您的时间差异会变小.