<slide title="Twit System Calls">

<blurb fontsize="3em">
Not much to see in the strace output.  But the favicon.ico effect is interesting
</blurb>

<example fontsize="1em" type="shell" title="All the syscalls for the app"><![CDATA[accept(4, {sa_family=AF_INET6, sin6_port=htons(51899), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 31
fcntl(31, F_GETFD)                      = 0
fcntl(31, F_SETFD, FD_CLOEXEC)          = 0
getsockname(31, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [68719476764]) = 0
fcntl(31, F_GETFL)                      = 0x2 (flags O_RDWR)
fcntl(31, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
read(31, "GET / HTTP/1.1\r\nHost: twit.local"..., 8000) = 501
stat("/var/www/twit/", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/var/www/twit/index.php", {st_mode=S_IFREG|0644, st_size=5938, ...}) = 0
setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={60, 0}}, NULL) = 0
rt_sigaction(SIGPROF, {0x7fd1652a4da0, [PROF], SA_RESTORER|SA_RESTART, 0x7fd168369530}, {0x7fd1652a4da0, [PROF], SA_RESTORER|SA_RESTART, 0x7fd168369530}, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0
getcwd("/home/rasmus/wp", 4095)         = 16
chdir("/var/www/twit")                  = 0
stat("././includes/db.inc", {st_mode=S_IFREG|0644, st_size=12915, ...}) = 0
stat("././includes/comments.inc", {st_mode=S_IFREG|0644, st_size=2285, ...}) = 0
stat("././includes/comment_msg.inc", {st_mode=S_IFREG|0644, st_size=544, ...}) = 0
stat("././includes/twit_msg.inc", {st_mode=S_IFREG|0644, st_size=3816, ...}) = 0
poll([{fd=32, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
write(32, "\1\0\0\0\16", 5)             = 5
read(32, "\7\0\0\1\0\0\0\2\0\0\0", 16384) = 11
poll([{fd=32, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
*write(32, ")\0\0\0\3SELECT \* from tracks  order"..., 45) = 45*
read(32, "\1\0\0\1\0031\0\0\2\3def\5twits\6tracks\6track"..., 16384) = 511
poll([{fd=32, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
*write(32, "\266\0\0\0\3SELECT query, count(id) as "..., 186) = 186*
read(32, "\1\0\0\1\7/\0\0\2\3def\5twits\5twits\5twits\5"..., 16384) = 467
poll([{fd=32, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
*write(32, "M\0\0\0\3SELECT \* from twits where a"..., 81) = 81*
read(32, "\1\0\0\1\r)\0\0\2\3def\5twits\5twits\5twits\2"..., 16384) = 736
poll([{fd=32, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
*write(32, "O\0\0\0\3SELECT \* from twits where s"..., 83) = 83*
read(32, "\1\0\0\1\r)\0\0\2\3def\5twits\5twits\5twits\2"..., 16384) = 1228
poll([{fd=32, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
*write(32, "O\0\0\0\3SELECT \* from twits where s"..., 83) = 83*
read(32, "\1\0\0\1\r)\0\0\2\3def\5twits\5twits\5twits\2"..., 16384) = 1896
poll([{fd=32, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
write(32, "Y\0\0\0\3select id,c_id,p_id,replies"..., 93) = 93
read(32, "\1\0\0\1\7/\0\0\2\3def\5twits\10comments\10com"..., 16384) = 700
stat("././includes/header.php", {st_mode=S_IFREG|0644, st_size=353, ...}) = 0
poll([{fd=32, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
*write(32, ")\0\0\0\3SELECT \* from tracks  order"..., 45) = 45*
read(32, "\1\0\0\1\0031\0\0\2\3def\5twits\6tracks\6track"..., 16384) = 511
chdir("/home/rasmus/wp")                = 0
setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
writev(31, [{"HTTP/1.1 200 OK\r\nDate: Sat, 06 M"..., 336}, {"\37\213\10\0\0\0\0\0\0\3", 10}, {"\345[\353r\33\267\25\376\357\247\200\
327\323\330\351\210\334\v\257\242I:\36\305J\334\211\35\325\326L\376"..., 3020}, {"\276Q\222\21\3438\0\0", 8}], 4) = 3374
write(23, "127.0.1.1 - - [06/Mar/2010:00:50"..., 185) = 185
shutdown(31, 1 /\* send \*/)              = 0
poll([{fd=31, events=POLLIN}], 1, 2000) = 1 ([{fd=31, revents=POLLIN|POLLHUP}])
read(31, "", 512)                       = 0
close(31)                               = 0
read(5, 0x7fff40d70daf, 1)              = -1 EAGAIN (Resource temporarily unavailable)
accept(4, {sa_family=AF_INET6, sin6_port=htons(51900), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 31
fcntl(31, F_GETFD)                      = 0
fcntl(31, F_SETFD, FD_CLOEXEC)          = 0
getsockname(31, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [68719476764]) = 0
fcntl(31, F_GETFL)                      = 0x2 (flags O_RDWR)
fcntl(31, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
read(31, "GET /css/master.css HTTP/1.1\r\nHo"..., 8000) = 569
stat("/var/www/twit/css/master.css", {st_mode=S_IFREG|0644, st_size=3902, ...}) = 0
open("/var/www/twit/css/master.css", O_RDONLY) = 33
fcntl(33, F_GETFD)                      = 0
fcntl(33, F_SETFD, FD_CLOEXEC)          = 0
close(33)                               = 0
writev(31, [{"HTTP/1.1 304 Not Modified\r\nDate:"..., 174}], 1) = 174
write(23, "127.0.1.1 - - [06/Mar/2010:00:50"..., 219) = 219
shutdown(31, 1 /\* send \*/)              = 0
poll([{fd=31, events=POLLIN}], 1, 2000) = 1 ([{fd=31, revents=POLLIN|POLLHUP}])
read(31, "", 512)                       = 0
close(31)                               = 0
read(5, 0x7fff40d70daf, 1)              = -1 EAGAIN (Resource temporarily unavailable)
accept(4, {sa_family=AF_INET6, sin6_port=htons(51907), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 31
fcntl(31, F_GETFD)                      = 0
fcntl(31, F_SETFD, FD_CLOEXEC)          = 0
getsockname(31, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [68719476764]) = 0
fcntl(31, F_GETFL)                      = 0x2 (flags O_RDWR)
fcntl(31, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
read(31, "GET /twit.js HTTP/1.1\r\nHost: twi"..., 8000) = 548
stat("/var/www/twit/twit.js", {st_mode=S_IFREG|0644, st_size=6203, ...}) = 0
open("/var/www/twit/twit.js", O_RDONLY) = 33
fcntl(33, F_GETFD)                      = 0
fcntl(33, F_SETFD, FD_CLOEXEC)          = 0
close(33)                               = 0
writev(31, [{"HTTP/1.1 304 Not Modified\r\nDate:"..., 175}], 1) = 175
write(23, "127.0.1.1 - - [06/Mar/2010:00:50"..., 212) = 212
shutdown(31, 1 /\* send \*/)              = 0
poll([{fd=31, events=POLLIN}], 1, 2000) = 1 ([{fd=31, revents=POLLIN|POLLHUP}])
read(31, "", 512)                       = 0
close(31)                               = 0
read(5, 0x7fff40d70daf, 1)              = -1 EAGAIN (Resource temporarily unavailable)
accept(4, {sa_family=AF_INET6, sin6_port=htons(51908), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 31
fcntl(31, F_GETFD)                      = 0
fcntl(31, F_SETFD, FD_CLOEXEC)          = 0
getsockname(31, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [68719476764]) = 0
fcntl(31, F_GETFL)                      = 0x2 (flags O_RDWR)
fcntl(31, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
read(31, "GET /staff/rasmus.jpg HTTP/1.1\r\n"..., 8000) = 557
stat("/var/www/twit/staff/rasmus.jpg", {st_mode=S_IFREG|0644, st_size=12015, ...}) = 0
open("/var/www/twit/staff/rasmus.jpg", O_RDONLY) = 33
fcntl(33, F_GETFD)                      = 0
fcntl(33, F_SETFD, FD_CLOEXEC)          = 0
close(33)                               = 0
writev(31, [{"HTTP/1.1 304 Not Modified\r\nDate:"..., 152}], 1) = 152
write(23, "127.0.1.1 - - [06/Mar/2010:00:50"..., 221) = 221
shutdown(31, 1 /\* send \*/)              = 0
poll([{fd=31, events=POLLIN}], 1, 2000) = 1 ([{fd=31, revents=POLLIN|POLLHUP}])
read(31, "", 512)                       = 0
close(31)                               = 0
read(5, 0x7fff40d70daf, 1)              = -1 EAGAIN (Resource temporarily unavailable)
accept(4, {sa_family=AF_INET6, sin6_port=htons(51909), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 31
fcntl(31, F_GETFD)                      = 0
fcntl(31, F_SETFD, FD_CLOEXEC)          = 0
getsockname(31, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "::ffff:127.0.1.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [68719476764]) = 0
fcntl(31, F_GETFL)                      = 0x2 (flags O_RDWR)
fcntl(31, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
*read(31, "GET /favicon.ico HTTP/1.1\r\nHost:"..., 8000) = 399*
*stat("/var/www/twit/favicon.ico", 0x7fff40d70ab0) = -1 ENOENT (No such file or directory)*
*lstat("/var", {st_mode=S_IFDIR 0755, st_size=4096, ...}) = 0*
*lstat("/var/www", {st_mode=S_IFDIR 0755, st_size=4096, ...}) = 0*
*lstat("/var/www/twit", {st_mode=S_IFDIR 0755, st_size=4096, ...}) = 0*
*lstat("/var/www/twit/favicon.ico", 0x7fff40d70ab0) = -1 ENOENT (No such file or directory)*
*write(10, "[Sat Mar 06 00:50:26 2010] [erro"..., 101) = 101*
*stat("/var/www/twit/404.php", {st_mode=S_IFREG 0644, st_size=364, ...}) = 0*
setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={60, 0}}, NULL) = 0
rt_sigaction(SIGPROF, {0x7fd1652a4da0, [PROF], SA_RESTORER|SA_RESTART, 0x7fd168369530}, {0x7fd1652a4da0, [PROF], SA_RESTORER|SA_RESTART, 0x7fd168369530}, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0
getcwd("/home/rasmus/wp", 4095)         = 16
chdir("/var/www/twit")                  = 0
chdir("/home/rasmus/wp")                = 0
setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
writev(31, [{"HTTP/1.1 302 Found\r\nDate: Sat, 0"..., 292}, {"\37\213\10\0\0\0\0\0\0\3", 10}, {"\3\0", 2}, {"\0\0\0\0\0\0\0\0", 8}], 
4) = 312
write(23, "127.0.1.1 - - [06/Mar/2010:00:50"..., 195) = 195
shutdown(31, 1 /\* send \*/)              = 0
poll([{fd=31, events=POLLIN}], 1, 2000) = 1 ([{fd=31, revents=POLLIN|POLLHUP}])
read(31, "", 512)                       = 0
close(31)                               = 0
read(5, 0x7fff40d70daf, 1)              = -1 EAGAIN (Resource temporarily unavailable)
accept(4,  <unfinished ...>]]></example>

<blurb fontsize="3em">
Not much else to do here.  378 req/sec and 10ms latency is about as good as it gets from
this little machine.  We can also look at the xhprof output and the xdebug callgraph where
we see that the Database is the bottleneck, as it should be.
</blurb>

<image filename="twit_xdebug.png" width="977" height="578" align="center"/>

<blurb fontsize="3em">
And the include hierachy is nice and flat. 
</blurb>

<image filename="twit_inclued.png" width="981" height="203" align="center"/>

<break lines="1"/>
</slide>
