티스토리 뷰

Tools

cURL HTTP 요청 속도 측정

구티맨 2020. 11. 30. 11:00

보통 로컬 PC에 있는 Postman 을 사용해서 HTTP 요청을 보내고, 속도가 얼마나 나오고 응답 크기가 얼만지 확인을 하는데

 

피치 못하게 보안상 이유로 방화벽 때문에 Postman 을 사용하지 못하는 경우가 있어

 

cURL 로 요청을 보내고, 응답을 파일에 저장 및 응답 속도를 출력하는 방법을 알아보겠습니다.

 

아래에 요청과 응답의 예제가 있습니다.

$ sudo curl -w "@curl-format.txt" -o response.json -XGET 'host:port/api'

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  118k    0  118k    0     0   199k      0 --:--:-- --:--:-- --:--:--  199k
time_namelookup:  0.000s
time_connect:  0.003s
time_appconnect:  0.000s
time_pretransfer:  0.003s
time_redirect:  0.000s
time_starttransfer:  0.587s
----------
time_total:  0.596s

 

-w 옵션은 요청을 완료하고 난 뒤에 무엇을 출력할지에 대한 포맷을 지정해 줄 수 있습니다.

 

-o 옵션은 stdout으로 결과를 출력하는 대신에, file에 출력하도록 해줍니다.

 

그래서 http 요청의 응답은 response.json에 저장을 하고,

 

응답 속도는 curl-format.txt 에 작성된 포맷대로 stdout에 출력을 해줍니다.

time_namelookup:  %{time_namelookup}s\n
time_connect:  %{time_connect}s\n
time_appconnect:  %{time_appconnect}s\n
time_pretransfer:  %{time_pretransfer}s\n
time_redirect:  %{time_redirect}s\n
time_starttransfer:  %{time_starttransfer}s\n
----------\n
time_total:  %{time_total}s\n

curl 요청에 걸리는 시간을 출력하기 위한 포맷(curl-format.txt)은 위와 같습니다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함