Tải bản đầy đủ - 0 (trang)
Chapter 20. Beyond Web Developer Tools: Strace

Chapter 20. Beyond Web Developer Tools: Strace

Tải bản đầy đủ - 0trang

Getting Started

To use it: open a terminal and invoke strace at the command prompt. This invocation

prints all system calls while starting Google Chrome to google.com:

$ strace -f -ttt -T google-chrome http://www.google.com/



I’ve added -f to follow forks, -ttt to print the timestamp of each call and -T to print

the duration of each call.



Zeroing In

If you run the preceding command, you’ll probably be overwhelmed by the amount of

stuff going on in a modern web browser. To filter down to something interesting, try

using the -e argument. For examining only file or network access, try -e trace=file or e trace=network. The man page (http://linux.die.net/man/1/strace) has many more examples.



Example: Local Storage

As a concrete example, let’s trace local storage performance in Chrome. First I opened

a local storage quota test page (http://arty.name/localstorage.html). Then I retrieved the

Chrome browser processes’ ID from Chrome’s task manager (Wrench > Tools > Task

Manager) and attached strace to that process using the -p switch.

$ strace -f -T -p __ -e trace=open,read,write



The output shows the timestamps, arguments and return value of every open, read, and

write system call. The man page for each call explains the arguments and return values.

The first call of interest to us is this open:

open("/home/tonyg/.config/google-chrome/Default/Local

Storage/

http_arty.name_0.localstorage-journal", O_RDWR|O_CREAT, 0640) = 114 <0.000391>



This shows us that Chrome has opened this file for reading and writing (and possibly

created it). The name of the file is a big clue that this is where local storage is saved for

arty’s web page. The return value, 114, is the file descriptor, which will identify it in

later reads and writes. Now we can look for read and write calls which operate on fd

114, for example:

write(114,

"\0\0\00020\0001\0002\0003\0004\0005\0006\0007\0008\0009\0000\0001\0002\0003\0

"..., 1024 <... write resumed> ) = 1024 <0.425476>



These two lines show a 1,024 byte write of the data beginning with the string above to

the local storage file (114). This write happened to take 425ms. Note that the call is



120 | Chapter 20: Beyond Web Developer Tools: Strace



www.it-ebooks.info



split into two lines with possibly others in between because another thread preempted

it. This is common for slower calls like this.



We’ve Only Scratched the Surface

There are options for dumping the full data read/written from the network or filesystem. Running with -c displays aggregate statistic about the time spent in the most

common calls. I’ve also found that some practical python scripting can quickly parse

these traces into a variety of useful formats.

This brief introduction hardly does this tool justice. I merely hope it provides the courage to explore deeper into the stack the next time you run into a tricky performance

problem.

To comment on this chapter, please visit http://calendar.perfplanet.com/

2011/beyond-web-developer-tools-strace/. Originally published on Dec

20, 2011.



We’ve Only Scratched the Surface | 121



www.it-ebooks.info



www.it-ebooks.info



CHAPTER 21



Introducing mod_spdy: A SPDY

Module for the Apache HTTP Server



Bryan McQuade and Matthew Steele

At Google, we strive to make the whole Web fast. Our work in this area includes Page

Speed Online, mod_pagespeed, Page Speed Service, Google Chrome, making TCP

faster, and the SPDY protocol, among other efforts. The SPDY (pronounced “SPeeDY”)

protocol allows websites to be transmitted more efficiently to the web browser, resulting in page load time improvements (http://blog.chromium.org/2009/11/2x-faster-web

.html) of as much as 55%. To make it easier for websites to realize the benefits of SPDY,

we’re releasing the source code for mod_spdy, an open-source module for the Apache

HTTP server.



Getting Started with mod_spdy

mod_spdy is still in early beta, and is not yet recommended for deployment in production environments. If you’d like to test out mod_spdy and help us to make it better,

please consult our Getting Started guide. We hoped to make it production-ready sometime in early 2012. Stay tuned by subscribing to our discussion forum.



SPDY and Apache

mod_spdy is an Apache 2.2-compatible module that provides SPDY support for Apache

HTTP servers. Multiplexing is an important performance feature of SPDY which allows

for multiple requests in a single SPDY session to be processed concurrently, and their

responses interleaved down the wire. However, due to the serialized nature of the

HTTP/1.1 protocol, the Apache HTTP server provides a one-request-per-connection

architecture. Apache’s connection and request processing normally happens in a single

thread, like shown on Figure 21-1.



123



www.it-ebooks.info



Figure 21-1. Apache’s connection and request processing



This works well for HTTP, but it presents a problem for multiplexed protocols like

SPDY because in this flow, each connection can only process one request at a time.

Once Apache starts processing a request, control is transferred to the request handler

and does not return to the connection handler until the request is complete.

To allow for SPDY multiplexing, mod_spdy separates connection processing and request processing into different threads. The connection thread is responsible for decoding SPDY frames and dispatching new SPDY requests to the mod_spdy request

thread pool. Each request thread can process a different HTTP request concurrently.

The diagram on Figure 21-2 shows the high-level architecture.

To learn more about how mod_spdy works within Apache, consult our wiki (http://

code.google.com/p/mod-spdy/wiki/HowItWorks).



Help to Improve mod_spdy

You can help us to make mod_spdy better by doing compatibility and performance

testing, by reviewing the code (http://code.google.com/p/mod-spdy/source/browse/trunk/

src#src%2Fmod_spdy%2Fcommon) and sending us feedback on the mod_spdy discussion list (https://groups.google.com/group/mod-spdy-discuss). We look forward to

your contributions and feedback!

To comment on this chapter, please visit http://calendar.perfplanet.com/

2011/introducing-mod_spdy-a-spdy-module-for-the-apache-http

-server/. Originally published on Dec 21, 2011.



124 | Chapter 21: Introducing mod_spdy: A SPDY Module for the Apache HTTP Server



www.it-ebooks.info



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 20. Beyond Web Developer Tools: Strace

Tải bản đầy đủ ngay(0 tr)

×
x