วัดเวลาถึงครั้งแรกสำหรับ URL เดี่ยวหรือหลาย URL สามารถแสดงค่า TTFB ที่เร็วที่สุดและช้าที่สุดและค่ามัธยฐานและเลือกบันทึกส่วนหัวการตอบกลับทั้งหมด

Usage: ttfb [options] url [url...]
-d debug
-l <log file> (infers -d) log response headers. Defaults to ./curl.log
-n <number> of times to test time to first byte
-o <option> pass options to curl (e.g. -o "-k" will make curl ignore invalid certificates)
-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)
ตามห่วงโซ่การเปลี่ยนเส้นทางโดยปริยายโดยใช้ตัวเลือก -L ของ Curl
สามารถบันทึกส่วนหัวการตอบกลับทั้งหมด (ไฟล์บันทึกเริ่มต้นคือ ./curl.log ) โดยการโทรด้วย -d
แทนที่ไฟล์บันทึกเริ่มต้นโดยระบุ -l /some/file
รับค่า TTFB ที่เร็วที่สุดช้าที่สุดและเฉลี่ยโดยระบุจำนวนครั้งที่จะเรียก URL ใช้ -n2 สำหรับ 2 การทดสอบ -n5 สำหรับ 5 และอื่น ๆ
ใช้การคำนวณ %{time_starttransfer¹} - %{time_appconnect²} ซึ่งไม่รวมค่าใช้จ่ายการเชื่อมต่อใด ๆ
¹ time_starttransfer
เวลาในไม่กี่วินาทีก็ใช้เวลาตั้งแต่เริ่มต้นจนกระทั่งไบต์แรกกำลังจะถูกถ่ายโอน ซึ่งรวมถึง time_pretransfer และเวลาที่เซิร์ฟเวอร์ที่จำเป็นในการคำนวณผลลัพธ์
² time_appconnect
เวลาในไม่กี่วินาทีก็ใช้เวลาตั้งแต่เริ่มต้นจนถึง SSL/SSH/ETC Connect/Handshake ไปยังโฮสต์ระยะไกลเสร็จสมบูรณ์
ขึ้นอยู่กับส่วนสำคัญของ https://github.com/sandeepraju
แก้ไขโดย [email protected], @jaygooby
ดาวน์โหลดสคริปต์จากสาขาหลักและทำให้สามารถดำเนินการได้:
curl -LJO https://raw.githubusercontent.com/jaygooby/ttfb.sh/master/ttfb
chmod +x ./ttfb
Usage: ttfb [options] url [url...]
-d debug
-l <log file> (infers -d) log response headers. Defaults to ./curl.log
-n <number> of times to test time to first byte
-o <option> pass options to curl (e.g. -o "-k" will make curl ignore invalid certificates)
-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)
การใช้งานขั้นพื้นฐาน:
$ ttfb example.com
.227436
การใช้งานขั้นพื้นฐานด้วยการแยกการตอบกลับ verbose:
$ ttfb -v https://example.com
DNS lookup: 0.005152 TLS handshake: 0.000000 TTFB including connection: 0.200831 TTFB: .200831 Total time: 0.201132
ทดสอบหลายครั้ง:
$ ttfb -n 5 example.com/example/url
.....
fastest .177263 slowest .214302 median .179957
ทดสอบ URL หลายรายการ:
$ ttfb bbc.co.uk news.bbc.co.uk
bbc.co.uk .049985
news.bbc.co.uk .054122
ทดสอบ URL หลายรายการหลายครั้ง:
$ ttfb -n 5 bbc.co.uk news.bbc.co.uk
.....
.....
bbc.co.uk fastest .030936 slowest .057755 median .034663
news.bbc.co.uk fastest .031413 slowest .182791 median .035001
การตอบสนองการตอบสนองของ Verbose เมื่อมีการทดสอบหลายครั้ง:
$ ttfb -v -n 5 bbc.co.uk
DNS lookup: 0.005335 TLS handshake: 0.102314 TTFB including connection: 0.148328 TTFB: .046014 Total time: 0.646115
DNS lookup: 0.005322 TLS handshake: 0.102609 TTFB including connection: 0.150693 TTFB: .048084 Total time: 0.644611
DNS lookup: 0.004277 TLS handshake: 0.102066 TTFB including connection: 0.172199 TTFB: .070133 Total time: 1.196256
DNS lookup: 0.004444 TLS handshake: 0.107375 TTFB including connection: 0.160771 TTFB: .053396 Total time: 0.637290
DNS lookup: 0.005352 TLS handshake: 0.118882 TTFB including connection: 0.168772 TTFB: .049890 Total time: 0.653761
fastest .046014 slowest .070133 median .049890
บันทึกส่วนหัวการตอบกลับทั้งหมดสำหรับการทดสอบหลายรายการไปยัง URL หลายรายการ:
ttfb -d -n 2 bbc.co.uk https://www.bbc.co.uk/weather
..
..
bbc.co.uk fastest .027550 slowest .055215 median .041382
https://www.bbc.co.uk/weather fastest .101020 slowest .297923 median .199471
$ ls *.log
bbc_co_uk-curl.log https___www_bbc_co_uk_weather-curl.log
$ cat https___www_bbc_co_uk_weather-curl.log
HTTP/2 200
server: openresty
x-cache-action: MISS
vary: Accept-Encoding,X-BBC-Edge-Cache,X-BBC-Edge-Scheme,X-CDN
x-cache-age: 0
cache-control: private, stale-while-revalidate=10, max-age=0, must-revalidate
content-type: text/html;charset=utf-8
x-mrid: w1
date: Thu, 11 Apr 2019 17:08:07 GMT
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-lb-nocache: true
x-msig: 24e37f81323984e4e45b8048f9e3c94a
x-frame-options: SAMEORIGIN
content-length: 1077454
HTTP/2 200
server: openresty
x-cache-action: MISS
vary: Accept-Encoding,X-BBC-Edge-Cache,X-BBC-Edge-Scheme,X-CDN
x-cache-age: 0
cache-control: private, stale-while-revalidate=10, max-age=0, must-revalidate
content-type: text/html;charset=utf-8
x-mrid: w1
date: Thu, 11 Apr 2019 17:08:08 GMT
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-lb-nocache: true
x-msig: 24e37f81323984e4e45b8048f9e3c94a
x-frame-options: SAMEORIGIN
content-length: 1077454
ดู https://blog.cloudflare.com/a-question-of-timing/ และ https://curl.haxx.se/docs/manpage.html สำหรับคำอธิบายว่าตัวแปรม้วนเกี่ยวข้องกับขั้นตอนต่าง ๆ ของการถ่ายโอนอย่างไร
เพื่อให้ได้การประมาณ TTFB ของ Devtool ที่ดีขึ้นเราจะพิจารณาเวลาที่ไม่มีค่าใช้จ่ายในการเชื่อมต่อ: %{time_starttransfer} - %{time_appconnect}
ใช้ eval สกปรกเพื่อทำเลขคณิต TTFB ขึ้นอยู่กับคำสั่ง bc และ column
หากคุณต้องการส่ง PR โปรดตรวจสอบให้แน่ใจว่าผ่านการทดสอบที่มีอยู่ทั้งหมดและหากเพิ่มฟังก์ชั่นใหม่ให้เพิ่มการทดสอบในชุดทดสอบ
ในการเรียกใช้การทดสอบโทร make จากรูทโครงการ คุณจะต้องติดตั้งค้างคาว-คอร์และใน $PATH ของคุณ
หากคุณต้องการเรียกใช้การทดสอบเพียงสองครั้งเท่านั้นให้ไม่ลงรอยกัน # skip lines ในการทดสอบที่คุณไม่สนใจดังนั้นพวกเขาจึงอ่าน skip และจากนั้นการทดสอบเหล่านั้นจะถูกข้ามไป
ดู CONTRIBUTING.md เพิ่มเติมสำหรับ MD สำหรับรายละเอียดเพิ่มเติม
แสดงความคืบหน้าเมื่อตั้งค่าตัวเลือกมากกว่าหนึ่งคำขอ ( -n 2 ฯลฯ )
-o ) จัดเรียงเอาต์พุตโดย TTFB ที่เร็วที่สุดเมื่อจัดหา URL หลายรายการ
รหัสสี TTFB: รูปในการตอบสนองมาตรฐานตามความเร็วของการตอบสนอง