Latency in GET requests

0

Hello.

I wrote a code in Python that extracts data from the FTX exchange using their API. I am running the code in an AWS instance (free plan, t2.micro), located very closeby to the servers of the exchange.

The code is essentially an infinite loop. At each step, it sends 3 'GET' requests, elaborates the response, and then goes to the next step. For the first few hundred iterations, the latency (defined below at the end of the post) for each block of three requests is of the order of 0.3seconds. After some time, it starts to grow up, reaching values from 2 to 5 seconds. In my local computer, located in the US, the latency is pretty constant at 1 second. There are no ratelimits in the FTX API for GET requests, so I should not expect any limit from the server. Is AWS limiting the rate of GET requests that I can make?

I am trying to understand the origin of this extra-latency. To do so, I have monitored the https data traffic with tcpdump and I have modified the python script so that it stops as soon as it experiences a latency > 2 seconds. In this way, I can isolate the last packets in the tcpdump output and try to understand the origin of the delay.

However, I really don't know how to read the output (I uploaded it here https://pastebin.com/tAhcicPU). Can anyone help me to understand the origin of the latency? 104.18.33.31.443 is the IP of FTX server 172.31.9.8 is the IP of the machine where my code runs

Definition of latency used here: I post the relevant part of the code where I compute the latency

latency=0
for pair in pairList:  # pairList  = ['BTC/USD','ETH/BTC','ETH/USD']
    api=requests.get(f'https://ftx.com/api/markets/{pair}/orderbook?depth={20}')
	latency+=api.elapsed.total_seconds()
return latency

So, it is the total sum of the latency returned by the requests.get for each request.

1개 답변
0

T-series instances use a concept of "burstable" performance where the instances has a number of CPU credits; when busy these are used; when idle credits build up. If there are no credits then the performance of the instance returns to a (lower) baseline. What you might be seeing is that you're running out of CPU credits. You can monitor the CPU credits so that might be worthwhile checking.

If this is causing the latency you might consider other instance types that do not use CPU credits (which is every other instance type) or you can enable Unlimited mode - noting that both of these solutions will have extra costs; and if you're using Unlimited mode all the time it it's best to consider a non-burstable instance type.

profile pictureAWS
전문가
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠