36
session code S308357 Angelo Rajadurai Sr. Technology Evangelist – Sun Microsystems Inc. Observing Your App and Everything Else It Runs On Using DTrace Sunday, May 31, 2009

DTrace and Drupal

Embed Size (px)

DESCRIPTION

Understand the need for dynamic tracing. See how you can use a tool like dtrace to observe a live running application. Deep dive into drupal using DTrace

Citation preview

Page 1: DTrace and Drupal

session code S308357

Angelo RajaduraiSr. Technology Evangelist – Sun Microsystems Inc.

Observing Your App and Everything Else It Runs On Using DTrace

Sunday, May 31, 2009

Page 2: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Learn how to Dynamically observe your application and its environment.

goal

Sunday, May 31, 2009

Page 3: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 3

your app...

Native Apps

ruby

C C++

Database MySQL/Oracle/Postgres

Operating System Solaris/Linux/OS X/Windows

Container Glassfish/J2EE

Frameworks

Application Logic

PresentationJSP/Javascript/Ajax/JavaFX

python

phpperl

shell

Apps run in VM

java

Sunday, May 31, 2009

Page 4: DTrace and Drupal

Amp Stack

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

4

OpenSolaris 2009.06

MySQL 5.1.30

Apache 2.2

Drupal 6.12

PHP - Zend 5.2

Our Setupon the menu today

Sunday, May 31, 2009

Page 5: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

the AMP stackTo build, install, integrate, performance tune and deploy

the amp stack on opensolaris...

# pkg install amp-dev

5

one small easy step

Sunday, May 31, 2009

Page 6: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 6

one slide on Drupal

Sunday, May 31, 2009

Page 7: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 7

How much time am I spending in Apache/

MySQL/PHP?How much of my load is from anonymous users

What type of database load is caused by anonymous users

What are the Drupal modules that take up

the most time?

What are the most expensive hooks in a given Drupal module?

questions questions questions

Sunday, May 31, 2009

Page 8: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 8

the big game hunt

Devel

oper:

“I’d as

k the

datab

ase ad

min” Database Admin:

“May be the middleware guys

will know”

Sysadmin

“I don’t know! Ask the

Developer” Middlew

are Ex

pert:

“Lets

ask th

e Sysa

dmin”

Sunday, May 31, 2009

Page 9: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 9

the vicious cycle

Instrument Validate

Run in production

Collect infoProcess

Add Code Compile

Custom Instruments

Stop App Restart w/ flags

Prebuilt Instruments

Sunday, May 31, 2009

Page 10: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 10

Please let me observe a live system.

oh please

Sunday, May 31, 2009

Page 11: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 11

Native

cc++ph

perl pyth

o

rub

shellDatabase

Operating System Solaris/Linux/OS X/

Container Glassfish/Tomcat

Frameworks

Application Logic

PresentationJSP/Javascript/Ajax

dynamic tracing

12::SELECT id, name, symbol, conversion_rate FROM currencies WHEREstatus = 'Active' and deleted = 012::SELECT category, name, value FROM config12::SELECT id FROM outbound_email WHERE type = 'system'

Sunday, May 31, 2009

Page 12: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 12

Native

cc++ph

perl pyth

o

rub

shellDatabase

Operating System Solaris/Linux/OS X/

Container Glassfish/Tomcat

Frameworks

Application Logic

PresentationJSP/Javascript/Ajax

dynamic tracing

-> contentAreaClick -> getPreventDefault <- getPreventDefault<- contentAreaClick

Sunday, May 31, 2009

Page 13: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 13

DTrace

You can do it with...

Sunday, May 31, 2009

Page 14: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 14

Have you heard about it

Have you used it

Have you written d-scripts

poll

Sunday, May 31, 2009

Page 15: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 15

The D - Language

Basicsof

Dynamic Instrumentation

Sunday, May 31, 2009

Page 16: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 16

instrumentation format

/ /predicate when

{

}

actions do what

d-script

: : :provider module probe name whereprobe

Sunday, May 31, 2009

Page 17: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 17

command line version

dtrace command line

# dtrace -n probe’/predicate/{action}’

Sunday, May 31, 2009

Page 18: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 18

demo

Sunday, May 31, 2009

Page 19: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 19

aggregation

=> mmap mmap 5 <= mmap mmap 5 => munmap munmap 5 <= munmap munmap 5 => setcontext setcontext 5 <= setcontext setcontext 5 => getrlimit getrlimit 5 <= getrlimit getrlimit 5 => getpid getpid 5 <= getpid getpid 5 => setcontext setcontext 5 <= setcontext setcontext 5 => sysi86 sysi86 5 <= sysi86 sysi86 5 => brk brk 5 <= brk brk 5 => brk brk 5 <= brk brk 5 => xstat xstat 5 <= xstat xstat 5 => resolvepath resolvepath 5 <= resolvepath resolvepath 5 => open open 5 <= open open 5 => mmap mmap 5 <= mmap mmap 5 => mmap mmap 5 <= mmap mmap 5 => mmap mmap 5 <= mmap mmap 5 => mmap mmap 5 <= mmap mmap 5 => munmap munmap 5 <= munmap munmap 5 => memcntl memcntl 5 <= memcntl memcntl 5 => close close 5 <= close close 5 => xstat xstat 5 <= xstat xstat 5 => resolvepath resolvepath 5 <= resolvepath resolvepath 5 => open open 5 <= open open 5 => mmap mmap 5 <= mmap mmap 5 => mmap mmap 5 <= mmap mmap 5 => mmap mmap 5 <= mmap mmap 5 => mmap mmap 5 <= mmap mmap 5 => mmap mmap 5 <= mmap mmap 5 => munmap munmap 5 <= munmap munmap 5 => memcntl memcntl 5 <= memcntl memcntl 5 => close close 5 <= close close 5 => munmap munmap 5 <= munmap munmap 5 => ioctl ioctl 5 <= ioctl ioctl 5 => ioctl ioctl 5 <= ioctl ioctl 5 => brk brk 5 <= brk brk 5 => brk brk 5 <= brk brk 5 => fsat fsat 5 <= fsat fsat 5 => fcntl fcntl 5 <= fcntl fcntl 5 => fstat64 fstat64 5 <= fstat64 fstat64 5 => getdents64 getdents64 5 <= getdents64 getdents64 5 => getdents64 getdents64 5 <= getdents64 getdents64 5 => close close 5 <= close close 5 => ioctl ioctl 5 <= ioctl ioctl 5 => fstat64 fstat64 5 <= fstat64 fstat64 5 => write write 5 <= write write 5 => close close 5 <= close close 5 => close close 5 <= close close 5 => rexit rexit

rexit 1 fcntl 2 fsat 2 getpid 2 getrlimit 2 sysi86 2 write 2 fstat64 4 getdents64 4 memcntl 4 open 4 resolvepath 4 setcontext 4

xstat 4 ioctl 6

brk 8 munmap 8 close 10 mmap 20

dtrace -P syscall

dtrace -P syscall’{@=count(probefunc)}’

Sunday, May 31, 2009

Page 20: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 20

dtrace aggregates - demo

Sunday, May 31, 2009

Page 21: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

the pid provider

• Dynamically create probes in live running applications.

• No extra work needed from application developer

• Available without any compile or runtime flags

• Can be created on optimized binaries as well

• Probes created at function boundaries and offset

21

provider: pid$<processId>module: name of libraryprobe: function namename: entry

return offset

Pid

ProviderSunday, May 31, 2009

Page 22: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 22

demo

Sunday, May 31, 2009

Page 23: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

probing MySQL using Pid

23

provider: pid$<mysql-pid>module: not-usedprobe:*dispatch_command*name: entry arg2 - SQL command

MySQ

L

Queries

#!/usr/sbin/dtrace -qspid$1::*dispatch_command*:entry{ printf("%s\n",copyinstr(arg2,arg3));}

Sunday, May 31, 2009

Page 24: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 24

dtrace and mysql - demo

Sunday, May 31, 2009

Page 25: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

php provider

compile-file-entry/-returnfunction-entry/-returnexecution-entry/-return

exception-thrown/-catchederror

request-startup/-shutdown

25

provider: php$<pid>module: not-usedprobe: not-used name: <see detail ->

Apache

Provider

New and improved in OpenSolaris 2009.06

Older releases

function-entry/-return

Sunday, May 31, 2009

Page 26: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 26

dtrace and php - demo

Sunday, May 31, 2009

Page 27: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Apache provider

received-requestlog-requestcreate-child

accept-connectioncheck-user-credentials

check-accesscheck-authorization

27

provider: apache$<pid>module: not-usedprobe: not-used name: <see detail ->

Apache

ProviderSunday, May 31, 2009

Page 28: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 28

gotcha

Sunday, May 31, 2009

Page 29: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 29

dtrace and the webstack

Sunday, May 31, 2009

Page 30: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Observing the entire stack

More details on the scripts we saw earlier...

what are the hot modules in Drupal?

what are the hot hooks in Drupal?

how much of my Drupal load is from anonymous users

how much time am I spending in Apache/MySQL/PHP?

what are the SQL statements that are executed by anon users

30

Sunday, May 31, 2009

Page 31: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Give me more!

DTrace landing page:http://www.opensolaris.org/os/community/dtrace

DTrace Toolkit:In OpenSolaris - /opt/DTTSolaris download -http://www.opensolaris.org/os/community/dtrace/dtracetoolkit/

DTrace Bigadmin page:http://www.sun.com/bigadmin/content/dtrace/

Lots and lots of info on the web - Google “dtrace”

31

Sunday, May 31, 2009

Page 32: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Social

My Blog:http://blogs.sun.com/angelo

Twitter:rajadurai

DTrace hands on labhttp://developers.sun.com/learning/javaoneonline/j1lab.jsp?lab=LAB-9400&yr=2008&track=1

32

Sunday, May 31, 2009

Page 33: DTrace and Drupal

session code S308357

Angelo [email protected]

Observing Your App and Everything Else It Runs On Using DTrace

Sunday, May 31, 2009

Page 34: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 34

DTrace and JavaScript

Sunday, May 31, 2009

Page 35: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Observing javascript using the javascript provider

Enter script details

35

Sunday, May 31, 2009

Page 36: DTrace and Drupal

2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 36

implementation

Sunday, May 31, 2009