Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

并发情况下,动态库 会加载1次还是 多次 #2

Open
munggruel opened this issue Apr 16, 2016 · 2 comments
Open

并发情况下,动态库 会加载1次还是 多次 #2

munggruel opened this issue Apr 16, 2016 · 2 comments

Comments

@munggruel
Copy link

ZEND_REGISTER_RESOURCE 是跨进程的,还是本进程有效

ZEND_REGISTER_RESOURCE 有一个进程注册了,另一个进程 需要再次注册 么

也就是说 并发情况下,动态库 会加载1次还是 多次

@munggruel
Copy link
Author

性能 和 纯c比 会有多少性能损失

@zuocheng-liu
Copy link
Owner

zuocheng-liu commented Apr 17, 2016

ZEND_REGISTER_RESOURCE 是单个进程中进行的,多个进程间不会共享,保存resource资源的结构体,在每个进程中维护。(进程间共享数据的方式,只有信号、信号量,unix域、管道、共享内存,消息队列那几种)

一般情况下,操作系统为单个进程运行时加载相同动态库只需加载1次。但是PNI使用fnctl库中 dlopen,dlclose,完全可以动态加载和关闭动态链接库。PNI还做了一个优化,把打开的动态链接库句柄持久化,这样PNI打开相同的动态链接库只要加载1次即可。

并发情况下,因为php-fpm 使用Fastcgi模式,也就是多进程模型。 这样每个进程启动都会动态加载1次动态链接库,但是每个进程可以被重复使用,去多次处理不同请求,所以单个进程对动态库加载只需要1次,后面重复使用。

动态链接库和纯c相比,或者说与静态编译相比,有人做过测试,性能会损失3%左右,《程序员的自我修养》这本书上好像有提到。像PHP扩展这种,大多也都是以动态链接库的方式去加载的。

我看到您已经加QQ群啦,欢迎到群里聊啊。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants