Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Your JavaScript fell into my Unix

Your JavaScript fell into my Unix

Volodymyr Kyrylov

February 18, 2012
Tweet

More Decks by Volodymyr Kyrylov

Other Decks in Programming

Transcript

  1. Huh? •Node.js •V8 with event loop and IO abstraction •SmartOS

    •DTrace •in 2012 tech must feel like 2012 kudos to Joyent engineers Saturday, February 18, 12
  2. and •cloud hypervisor •zero configuration •no install •running from the

    USB stick • come on, it’s 2012, who installs and configures an OS today? •native Solaris Zones •KVM virtualization for others Saturday, February 18, 12
  3. kai# dtrace -Cs ./execsnoop.real.d [5125->5138] man man [5138->5139] sh -c

    /usr/bin/gunzip -c '/usr/share/man/man1/man.1.gz' [5138->5139] /bin/sh /usr/bin/gunzip -c /usr/share/man/man1/man. 1.gz [5138->5139] gzip -d -c /usr/share/man/man1/man.1.gz [5138->5140] sh -c /usr/bin/gunzip -c '/usr/share/man/man1/man.1.gz' [5147->5148] /usr/bin/less -is [5138->5140] /bin/sh /usr/bin/gunzip -c /usr/share/man/man1/man.1.gz [5138->5140] gzip -d -c /usr/share/man/man1/man.1.gz [5138->5141] sh -c (cd '/usr/share/man' && (echo ".ll 9.0i"; echo ".nr LL 9.0i"; /usr/bin/gunzip -c '/usr/share/man/man1/man.1.gz') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc - c | (/usr/bin/less -is || true)) [5143->5145] /bin/sh /usr/bin/gunzip -c /usr/share/man/man1/man.1.gz [5143->5145] gzip -d -c /usr/share/man/man1/man.1.gz [5142->5144] /usr/bin/tbl [5142->5146] /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c [5146->5150] grotty [5146->5149] troff -Wall -mtty-char -mandoc -c -Tascii Saturday, February 18, 12
  4. kai# gzcat /usr/share/man/man1/man.1.gz .TH man 1 "September 19, 2005" .LO

    1 .SH NAME man \- format and display the on-line manual pages .SH SYNOPSIS .B man .RB [ \-acdfFhkKtwW ] .RB [ --path ] .RB [ \-m .IR system ] .RB [ \-p .IR string ] .RB [ \-C .IR config_file ] .RB [ \-M .IR pathlist ] .RB [ \-P Saturday, February 18, 12
  5. [root@00-0c-29-c5-21-b9 ~]# vmadm Usage: /usr/sbin/vmadm <command> [options] create [-f <filename>]

    console <uuid> delete <uuid> get <uuid> info <uuid> [type,...] list [-p] [-H] [-o field,...] [-s field,...] [field=value ...] lookup [-j|-1] [field=value ...] reboot <uuid> [-F] start <uuid> [option=value ...] stop <uuid> [-F] sysrq <uuid> <nmi|screenshot> update <uuid> [-f <filename>] -or- update <uuid> property=value [property=value ...] For more detailed information on the use of this command,type 'man vmadm'. Saturday, February 18, 12
  6. [root@00-0c-29-c5-21-b9 ~] # dsadm avail | grep nodejs 475a1026-00a4-11e1-a2df-a71425f9c46b smartos

    2011-10-27 sdc:sdc:nodejs:1.3.0 41da9c2e-7175-11e0-bb9f-536983f41cd8 smartos 2011-04-28 sdc:sdc:nodejs:1.1.4 7456f2b0-67ac-11e0-b5ec-832e6cf079d5 smartos 2011-04-15 sdc:sdc:nodejs:1.1.3 Saturday, February 18, 12
  7. [root@00-0c-29-c5-21-b9 ~] # head -1 $(which dsadm) #!/usr/bin/env node [root@00-0c-29-c5-21-b9

    ~] # head -1 $(which vmadm) #!/usr/bin/node [root@00-0c-29-c5-21-b9 ~] # ls /usr/node_modules/ async.js kstat.node onlyif.js sprintf.js syslog.node system.js Saturday, February 18, 12
  8. DTrace • Dynamic Tracing Framework, first released for Solaris 10

    in 2004, open sourced in 2005 • a set of kernel modifications to hot-patch program text at run time • a programming language for control • a library to collect execution state and analyze it • provides observability across the entire software stack • Solaris/Illumos/SmartOS, Mac OS X, FreeBSD, Linux(!), NetBSD (some parts), QNX(?) Saturday, February 18, 12
  9. # cat example.d int64_t passed; BEGIN { ! trace("started"); !

    passed = 0; } tick-10s {} tick-10s { ! passed = walltimestamp; } END /passed != 0/ { ! printf("stopped after 10 seconds (at %Y)", passed); } Saturday, February 18, 12
  10. DTrace Providers • fbt: arbitrary function boundary tracing in kernel

    text • relies on correct function prologue/epilogue ABI • fasttrap: arbitrary instruction in user program text • like debuggers • sdt/usdt: statically defined tracing • arbitrary traps into DTrace (mostly for convenience and stability), replaced by nops when inactive • several special/custom providers (tick-Ns, profile-N, syscall and wrappers around above) Saturday, February 18, 12
  11. # dtrace -l | wc -l 178274 # ps -ef

    | wc -l 122 # nm /mach_kernel | wc -l 16110 ... Saturday, February 18, 12
  12. •Instrument production nodejs instance proxied by nginx •Access both simultaneously

    •No debuggers — no interruption! •No recompilation Hack Demo Saturday, February 18, 12
  13. oictl# cat /srv/www/vhost/iosdev.conf proxy_cache_path /tmp/cache1 levels=1:2 keys_zone=microcache:5m max_size=1000m; ... server

    { listen 80; server_name iosdev.org.ua; location / { proxy_pass http://localhost:5000; proxy_set_header X-Real-IP $remote_addr; proxy_cache microcache; proxy_cache_key $scheme$host$request_method$request_uri; proxy_cache_valid 200 20s; proxy_cache_use_stale updating; } location /assets { ... } ... } ... Saturday, February 18, 12
  14. oictl# (pgrep node; pgrep nginx) | wc -l 7 oictl#

    nm $(which nginx) | grep http_file_cache_new [3470] | 135498072| 137|FUNC |GLOB |0 |13 |ngx_http_file_cache_new oictl# pgrep nginx | xargs -n1 printf "-n 'pid%s::ngx_http_file_cache_new:entry {}' "; echo -n 'pid808::ngx_http_file_cache_new:entry {}' -n 'pid19856::ngx_http_file_cache_new:entry {}' -n 'pid19859::ngx_http_file_cache_new:entry {}' -n 'pid19858::ngx_http_file_cache_new:entry {}' -n 'pid19857::ngx_http_file_cache_new:entry {}' -n 'pid19855::ngx_http_file_cache_new:entry {}' # copy-paste oictl# rm -rf /tmp/cache1/* oictl# dtrace -n 'pid808::ngx_http_file_cache_new:entry {}' -n 'pid19856::ngx_http_file_cache_new:entry {}' -n 'pid19859::ngx_http_file_cache_new:entry {}' -n 'pid19858::ngx_http_file_cache_new:entry {}' -n 'pid19857::ngx_http_file_cache_new:entry {}' -n 'pid19855::ngx_http_file_cache_new:entry {}' -n 'node*:::http-server-response {}' dtrace: description 'pid808::ngx_http_file_cache_new:entry ' matched 1 probe dtrace: description 'pid19856::ngx_http_file_cache_new:entry ' matched 1 probe dtrace: description 'pid19859::ngx_http_file_cache_new:entry ' matched 1 probe dtrace: description 'pid19858::ngx_http_file_cache_new:entry ' matched 1 probe dtrace: description 'pid19857::ngx_http_file_cache_new:entry ' matched 1 probe dtrace: description 'pid19855::ngx_http_file_cache_new:entry ' matched 1 probe dtrace: description 'node*:::http-server-response ' matched 1 probe CPU ID FUNCTION:NAME 0 73189 _ZN4node27DTRACE_HTTP_SERVER_RESPONSEERKN2v89ArgumentsE:http-server-response 1 73210 ngx_http_file_cache_new:entry 0 73189 _ZN4node27DTRACE_HTTP_SERVER_RESPONSEERKN2v89ArgumentsE:http-server-response 1 73210 ngx_http_file_cache_new:entry ^C Saturday, February 18, 12