thinkphp框架执行的系统调用

1512532163.625919 lstat("/usr/local/sbin/php", 0x7ffdbd917b90) = -1 ENOENT (No such file or directory) 626425-625919=506 微秒
1512532163.626425 lstat("/usr/local/bin/php", 0x7ffdbd917b90) = -1 ENOENT (No such file or directory) 627048-626425=623 微秒
1512532163.627048 lstat("/usr/sbin/php", 0x7ffdbd917b90) = -1 ENOENT (No such file or directory) 627541-627048=493 微秒
1512532163.627541 lstat("/usr/bin/php", {st_mode=S_IFLNK|0777, st_size=22, ...}) = 0

....

php代码
if(file_exists("pro.txt")){
define("CONF_ENV","pro");
}elseif(file_exists("test.txt")){
define("CONF_ENV","test");
}else{
define("CONF_ENV","dev");
}

对应的系统调用

1512532163.726184 access("pro.txt", F_OK) = -1 ENOENT (No such file or directory) 726970-726184=786 微秒
1512532163.726970 access("test.txt", F_OK) = -1 ENOENT (No such file or directory) 727728-726970=758 微秒
1512532163.727728 getcwd("/www/web/xuexi", 4096) = 15

......

1512532165.130860 stat("/www/web/ThinkPHP/Library/Home", 0x7ffdbd9170e0) = -1 ENOENT (No such file or directory) 132173-130860=1313微秒
1512532165.132173 stat("/www/web/xuexi/Application/Home/Model/CourseModel.class.php", 0x7ffdbd9170a0) = -1 ENOENT (No such file or directory) 133615-132173=1442微秒
1512532165.133615 stat("/www/web/ThinkPHP/Library/Common", 0x7ffdbd9170e0) = -1 ENOENT (No such file or directory)

......

1512532163.935557 stat("/www/web/xuexi/Application/Common/Conf/debug.php", 0x7ffdbd9177c0) = -1 ENOENT (No such file or directory) 936669-935557=1112 微秒
1512532163.936669 stat("/www/web/xuexi/Application/Home", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0

......

1512532169.216137 stat("/www/web/ThinkPHP/Library/Common", 0x7ffdbd917110) = -1 ENOENT (No such file or directory) 217161-216137=1024 微秒
1512532169.217161 stat("/www/web/xuexi/Application/Common/Behaviors/RenderBehavior.class.php", {st_mode=S_IFREG|0777, st_size=1134, ...}) = 0 218971-217161=1810 微秒
1512532169.218971 lstat("/www/web/xuexi/Application/Common/Behaviors/RenderBehavior.class.php", {st_mode=S_IFREG|0777, st_size=1134, ...}) = 0

可以看到越到后面越慢,可能越到后面打开的文件越多,造成io来不及,只能排队了。

 

 

然后看下原生php hello word调用

1512537604.693407 execve("/usr/bin/php", ["php", "index.php"], [/* 22 vars */]) = 0
1512537604.696775 brk(0) = 0x1664000
1512537604.697292 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f89d8e15000
1512537604.697554 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
1512537604.698038 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
1512537604.698959 fstat(3, {st_mode=S_IFREG|0644, st_size=94102, ...}) = 0
1512537604.699390 mmap(NULL, 94102, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f89d8df5000
1512537604.699902 close(3) = 0

......

1512537604.897966 getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
1512537604.898860 brk(0) = 0x17ee000
1512537604.899090 brk(0x180f000) = 0x180f000
1512537604.900001 brk(0) = 0x180f000
1512537604.900234 brk(0x1830000) = 0x1830000
1512537604.901168 mmap(NULL, 151552, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f89d8d47000

以上执行时间 901168-693407=207761 微秒,约200毫秒

====================================================真正的执行自己写的程序开始了=======================================================

1512537604.902271 open("index.php", O_RDONLY) = 3
//打开文件,返回文件描述为 3

1512537604.902593 fstat(3, {st_mode=S_IFREG|0644, st_size=18, ...}) = 0
//获取文件属性,fstat参数是指向这个文件的指针,也就是文件描述符3。
//还有经常看到stat() 和 lstat(),它们两人都是通过文件路径访问文件。
//1.当文件是符号链接时,lstat() 返回的是该符号链接本身的信息,拿window比方,就相当于返回了快捷方式的信息,一个古老的笑话,一个妹子拿软盘copy红警游戏,秒好,回家一打开不能用,就是把桌面上的快捷方式copy回去了。
//2. stat() 返回的是该该符号链接指向的文件的信息。也就是找到了幕后真正老大。

1512537604.902819 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f89d8e0b000
//将文件映射到内存,此处映射了4k,就是1页的空间。

1512537604.902998 read(3, " //读取4k数据,由于我们index.php 只有一个 echo "hi",就全读取出来了。 返回值18表示文件大小是18byte

1512537604.903232 lseek(3, 0, SEEK_SET) = 0
//将文件指针位置移到文件开头

1512537604.903407 getcwd("/root/php", 4096) = 10
1512537604.903757 lstat("/root/php/index.php", {st_mode=S_IFREG|0644, st_size=18, ...}) = 0
1512537604.904035 lstat("/root/php", {st_mode=S_IFDIR|0755, st_size=38, ...}) = 0
1512537604.904256 lstat("/root", {st_mode=S_IFDIR|0550, st_size=4096, ...}) = 0
1512537604.904755 rt_sigaction(SIGPROF, NULL, {SIG_DFL, [], 0}, 8) = 0
1512537604.905604 rt_sigaction(SIGPROF, {0x87fc00, ~[ILL TRAP ABRT BUS FPE KILL SEGV CONT STOP TSTP TTIN TTOU SYS RTMIN RT_1], SA_RESTORER|SA_SIGINFO, 0x7f89d3532250}, NULL, 8) = 0
1512537604.906108 rt_sigaction(SIGHUP, NULL, {SIG_DFL, [], 0}, 8) = 0
1512537604.906310 rt_sigaction(SIGHUP, {0x87fc00, ~[ILL TRAP ABRT BUS FPE KILL SEGV CONT STOP TSTP TTIN TTOU SYS RTMIN RT_1], SA_RESTORER|SA_SIGINFO, 0x7f89d3532250}, NULL, 8) = 0
1512537604.906520 rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0
1512537604.906740 rt_sigaction(SIGINT, {0x87fc00, ~[ILL TRAP ABRT BUS FPE KILL SEGV CONT STOP TSTP TTIN TTOU SYS RTMIN RT_1], SA_RESTORER|SA_SIGINFO, 0x7f89d3532250}, NULL, 8) = 0

......

1512537604.908183 rt_sigaction(SIGUSR2, NULL, {SIG_DFL, [], 0}, 8) = 0
1512537604.908392 rt_sigaction(SIGUSR2, {0x87fc00, ~[ILL TRAP ABRT BUS FPE KILL SEGV CONT STOP TSTP TTIN TTOU SYS RTMIN RT_1], SA_RESTORER|SA_SIGINFO, 0x7f89d3532250}, NULL, 8) = 0
1512537604.908629 rt_sigaction(SIGPROF, {0x87fc00, ~[ILL TRAP ABRT BUS FPE KILL SEGV CONT STOP TSTP TTIN TTOU SYS RTMIN RT_1], SA_RESTORER|SA_SIGINFO, 0x7f89d3532250}, NULL, 8) = 0
1512537604.908848 rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0
1512537604.909158 mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f89d8dfb000
1512537604.909805 fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
1512537604.910047 fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
1512537604.910253 lseek(0, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
1512537604.910447 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
1512537604.910669 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
1512537604.910878 lseek(1, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
1512537604.911079 fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
1512537604.911281 fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
1512537604.911828 lseek(2, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
1512537604.912131 getcwd("/root/php", 4096) = 10
1512537604.912538 stat("/etc/sysconfig/64bit_strstr_via_64bit_strstr_sse2_unaligned", 0x7ffd3a069e70) = -1 ENOENT (No such file or directory)
1512537604.912824 ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3a069d50) = -1 ENOTTY (Inappropriate ioctl for device)
1512537604.913056 fstat(3, {st_mode=S_IFREG|0644, st_size=18, ...}) = 0
1512537604.913258 mmap(NULL, 50, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f89d8d45000
1512537604.913821 munmap(0x7f89d8d45000, 50) = 0
1512537604.914055 close(3) = 0
1512537604.914251 munmap(0x7f89d8e0b000, 4096) = 0
1512537604.914501 write(1, "hi", 2) = 2
//写入buff,等待后面print到页面上

1512537604.914937 close(2) = 0
1512537604.915125 close(1) = 0
1512537604.915299 close(0) = 0
1512537604.916316 munmap(0x7f89d8dfb000, 65536) = 0
1512537604.918345 munmap(0x7f89d8d47000, 151552) = 0
1512537604.919099 munmap(0x7f89d8d6c000, 151552) = 0
1512537604.919572 munmap(0x7f89cfa00000, 2097152) = 0
1512537604.919840 munmap(0x7f89d8d91000, 323584) = 0
1512537604.920936 exit_group(0) = ?
1512537604.923693 +++ exited with 0 +++

以上运行时间 923693-901168=22525微秒

初步统计了下,原生的调用有695次,使用thinkphp框架调用有2203次。多了1千多次调用。所以减少文件访问也是提高性能的方式,虽然提高的比较小。

Comments are closed.

Post Navigation