- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一些在 Apache 的 MPM prefork 服务器上建模的 Python 代码。我更像是一名应用程序程序员而不是网络程序员,自从我阅读 Stevens 以来已经有 10 年了,所以我正在努力加快理解代码的速度。
我找到了 how Apache's prefork code works, by Sander Temme 的简短描述.
The parent process, which typically runs as root, binds to a socket (usually port 80 or 443). It spawns children, which inherit the open file descriptor for the socket, and change uid and gid to the unprivileged user and group. The children construct a pollset of the listener file descriptors (if there is more than one listener) and watch for activity on it/them. If activity is found, the child calls accept() on the active socket and handles the connection. When it is done with that, it returns to watching the pollset (or listener file descriptor).
Since multiple children are active and they all inherited the same socket file descriptor(s), they will be watching the same pollset. An accept mutex allows only a single child to actually watch the pollset, and once that has found an active socket it will unlock the mutex so the next child can start watching the pollset. If there is only a single listener, that accept mutex is not used and all children will hang in accept().
这几乎就是我正在查看的代码的工作方式,但我不明白一些事情。
1) “ child ”和“听众”有什么区别?我认为每个 child 都是一个监听器,这对于我正在查看的代码来说是正确的,但在 Temme 的描述中可以有“单个监听器”和“ child ”。 child 什么时候会有多个听众?
2) (与 1 相关)这是每进程互斥体还是系统互斥体?就此而言,为什么要有互斥体? Accept(2) 不会在所有监听器之间执行自己的互斥吗?我的研究表明我确实需要一个互斥体,并且互斥体必须遍及整个系统。 (群体、信号量等)
Temme 继续说道:
Children record in a shared memory area (the scoreboard) when they last served a request. Idle children may be killed by the parent process to satisfy MaxSpareServers. If too few children are idle, the parent will spawn children to satisfy MinSpareServers.
3)这个实现有没有好的引用代码(最好是Python)?我找到了Perl的Net::Server::Prefork ,它使用管道而不是记分板的共享内存。我找到了Randal Schwartz的文章它只进行预 fork ,但不进行记分板。
pre-fork example from the Perl Cookbook没有任何围绕 select 的锁定,并且 Chris Siebenmann's Python example说它基于 Apache,但使用配对套接字作为记分板,而不是共享内存,并使用套接字作为控件,包括对给定子项的控制以“接受”。这与 Apache 的描述完全不符。
最佳答案
就 (1) 而言,监听器只是对接受连接的套接字是否存在的引用。由于Apache可以同时接受多个套接字上的连接,例如80/443,因此有多个监听器套接字。每个子进程在需要时都需要监听所有这些套接字。由于accept()一次只能在一个套接字上执行,因此它之前是poll/select,因此知道应该在哪个监听器套接字上执行accept。
对于(2),它是全局或跨进程互斥体。也就是说,一个进程锁定它会阻止其他试图获取同一锁的进程。尽管accept()在技术上会序列化进程,但多个监听器套接字的存在意味着您不能依赖它,因为您事先不知道要在哪个套接字上执行接受。即使在单个监听器套接字的情况下,使用accept互斥锁的原因是,如果有大量进程处理请求,那么如果操作系统唤醒所有进程以查看哪些进程有accept()返回,那么成本可能会相当高。由于处于 prefork 模式的 Apache 可能有 100 多个进程,这可能会导致问题。
因此,如果您只有一个监听器套接字,并且知道只有几个进程想要执行accept() 调用,那么您可以取消跨进程accept 互斥体。
关于locking - 多个进程之间共享套接字的accept()(基于Apache preforking),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1293652/
只是想知道是否有可能找出谁从 Windows 共享中读取了文件(最好使用 .NET,但 win32 native 可以)? 我想做的是创建类似 awstats 的东西对于 Windows 共享,这样我
是否可以列出 Intent.ACTION_SEND ?我的意思是我需要知道是否有人通过 action_send 在 Facebook 上分享或在 Twitter 上发推文。 最佳答案 也许你想要一个更
我正在使用 Google Apps 应用程序。实际上,我想在不使用密码的情况下访问另一个 ID。我使用了 OAuth,它运行良好。但我无法分享特定人的日历。我尝试了以下代码。 GoogleOAuthP
我怎样才能只创建模拟器...可能吗?我知道,设备需要分发证书。 最佳答案 您只需将应用程序目录从 iPhone 模拟器复制到另一个实例/操作系统版本,它就应该可以工作。 因此,如果您想分发 3.1.3
我想使用多阶段构建来避免每次构建应用程序时都下载我的 Java 项目所需的所有 Maven 依赖项。 我正在考虑在第一阶段解决 Maven 依赖项,然后在第二阶段构建应用程序,这将需要访问在前一阶段下
我正在寻找保护用户下载内容的初步想法。用户下载充满有趣资源的 zip 文件,这些资源被提取到本地文件系统中以供应用程序使用。我的目标是防止用户通过互联网将下载的资源共享给其他用户(假设他们获得了对文件
我想知道在具有移动和桌面版本的网站上共享身份验证、 session 管理等的最佳方法是什么。我们正在运行 Tomcat,并且更愿意将移动站点和桌面站点的应用程序保持在不同的节点上。 我看过类似的帖子,
我发现了这个单例的实现。我怎样才能创建指向它的指针或共享指针?` 为什么这不起作用?自动测试 = Singleton::Instance(); class Singleton { public: st
我有一个 heroku 项目,我想与其他人分享。作为the instructions describe ,我使用 virtualenv 来管理环境和依赖项。有没有办法在新机器上从 requiremen
Maven 将所有 jar 存储在本地存储库 ~/.m2/repository/ 下。用户多时占用空间大。 那么,是否可以由多个用户共享这个本地存储库,或许在不同的目录结构下? 最佳答案 简单的回答
为什么共享 worker 在重新加载页面时死了?应该是复活了我该如何解决这个问题? 重装前 重新加载后(在example.com上按F5) parent worker var port = new S
我正在开发多个小型应用程序,这些应用程序将共享通用和共享模块和 Assets 。 关于如何创建项目结构的部分在这里回答:https://stackoverflow.com/a/61254557/135
我在 RHEL 上安装了 jenkins (localhost:8080),我能够成功地构建代码 现在,我想设置主/从代理。 我的笔记本电脑将充当“Master Jenkins”,而我同事的笔记本电脑
我有这种方法可以根据我使用的 EXTRA_STREAM 共享文本文件或图片。我有这两个我可以选择 i.putExtra(Intent.EXTRA_STREAM, uri); i.putExtra(In
我正在使用 R 中的一个数据分析项目,我正在使用 R 中的敏感私有(private)数据进行一些逻辑和多级建模。我爱上了 。预订 包,我已经创建了一本关于我们的工作流程和分析管道的相当广泛的书。问题是
我正在构建的应用程序需要在 UITabBarController 框架内为多个 View (及其 subview )显示共享的自定义 UIToolbar。自定义工具栏的内容在所有 View 中都是相同
我有多个应用程序,我想共享相同的 eslint 配置: - project_root/ - app1/ - node_modules/ - eslint.rc
我有多个 Electron 应用程序。一个是主应用程序,其他几个功能应用程序。主应用程序上的按钮很少,这将导致功能应用程序打开。这里的问题是每个应用程序都有一个主进程,该进程导致要利用更多的CPU。是
我正在开发一个 Node.js 后端,它通过 websocket 与一些桌面客户端进行通信,而服务器端的通信是从 Web 前端发起的。一切正常,因为我将 SockJS Connection 实例存储在
我对托管多个网站的服务器上的多个用户帐户使用私有(private) SSH key 和无密码条目。 我为每个用户帐户使用相同的私钥。 (因为我很懒?或者那是“正确”的方式)。 我现在想授权该国不同地区
我是一名优秀的程序员,十分优秀!