zoukankan      html  css  js  c++  java
  • 记一次apache+php调优

    近日手头拿到了一个调优问题,详细一看,发现是apache+php问题,问题的具体表现如下:

    正常运行的服务常常停止响应, 一旦停止响应, 维护人员就不得己需要去重启apache服务

    对php不熟,调查过程也顺便学习一下php的基本配置。

    2015-3-11 调试

    首先去服务器进程看了看,发现有一个 http.exe 在后台一直占用%50左右的 cpu,即使通过 Moniter 结束了服务,这个进程也依然坚挺,始终占用固定的CPU, 打开perfmon.exe,发现 内存换页频繁,且都是硬错误,估计就是那个进程导致的,直接结束之。 结果cpu一下子就下来了。

    又研究了部分参数设置,尤其是 mpm_module 相关的设置
    通过以下命令可以查看加载的模块

    httpd -l
    

    发现mpm_module的的加载情况和实际配置不符,windows系统中,其实只加载了后者,实际配置如下:

    # 配置了mpm_winnt_module以后,mpm_prefork_module就不起作用了
    # 可以通过 httpd -l查看当前加载的模块
    <IfModule mpm_prefork_module>
        StartServers          5
        MinSpareServers       5
        MaxSpareServers      10
        MaxClients          256
        MaxRequestsPerChild   500
    </IfModule>
    
    # mpm_winnt_module 该多路处理模块(MPM)是Windows NT上的默认值。它使用一个单独的父进程产生一个单独的子进程,在这个子进程中轮流产生多个线程来处理请求。StartServers定义的进行启动
    # ThreadsPerChild        200 启动的线程数,公司bbs平常都在20+,暂时这样配置节省内存资源
    # MaxRequestsPerChild    10000 这个模式只启动两个进程(httpd.exe)一主一子,子进程执行10000个请求以后会被终止,然后另起一个
    # Win32DisableAcceptEx Use accept() rather than AcceptEx() to accept network connections,
    # 另外重启apache时候,先关闭,并且结束所有httpd.exe,再启动,不要直接restart,会遗留下httpd的进程不关
    <IfModule mpm_winnt_module>
    	ThreadsPerChild         400
    	MaxRequestsPerChild     10000
    	Win32DisableAcceptEx
    </IfModule>
    

    apache官方文档中有如下说明

    AcceptEx()是一个微软的WinSock2 API ,通过使用BSD风格的accept() API提供了性能改善。一些流行的Windows产品,比如防病毒软件或虚拟专用网络软件,会干扰AcceptEx()的正确操作。如果遇到类似于如下的错误:

    [error] (730038)An operation was attempted on something that is not a socket.: winnt_accept: AcceptEx failed. Attempting to recover.

    就需要使用这个指令来禁止使用AcceptEx() 。

    对于windows操作系统,可以使用专用的mpm_winnt_module,来提高性能,但是参数配置要注意。

    2015-3-18 调试

    观察了几天,发现还是有问题,找错误日志去看了看,发现了一个问题

    FATAL:  erealloc():  Unable to allocate 98304 bytes
    

    每次运行到一个阶段,apache就会出现无法回收内存的严重问题,这样一来,用不了多久就得重启了

    经过调查,从apache的 bug 一路找过去,最后发现这个是php的一个 bug,但是都没有解决。。。

    最后又找了一阵子,发现一个 论坛 中有讨论,找到一句靠谱的话

    Looks like php related.
    You are using outdated/legacy PHP 4 and Apache 2.0, not anymore supported for quite some time.

    It is a known issue with a PHP before 5.3 that it has memory management and stability issues.

    #The most common solution for this kinfd of errors was using PHP with Fast CGI (mod_fcgid). I do not know there is still somewhere a version for Apache 2.0.

    Also I see also PHP warnings: Undefined variable: id_vue libelle_vue.

    随后我找了一个php5.2.7稳定版进行升级,升级以后,做了简单的并发访问,没有打印异常。
    继续观察观察

  • 相关阅读:
    jMeter 里 CSV Data Set Config Sharing Mode 的含义详解
    如何使用 jMeter Parallel Controller
    使用 Chrome 开发者工具 coverage 功能分析 web 应用的渲染阻止资源的执行分布情况
    使用 Chrome 开发者工具的 lighthouse 功能分析 web 应用的性能问题
    关于 SAP 电商云首页加载时触发的 OCC API 请求
    SAP UI5 确保控件 id 全局唯一的实现方法
    SAP 电商云 Accelerator 和 Spartacus UI 的工作机制差异
    介绍一个好用的能让网页变成黑色背景的护眼 Chrome 扩展应用
    Chrome 开发者工具 performance 标签页的用法
    Client Side Cache 和 Server Side Cache 的区别
  • 原文地址:https://www.cnblogs.com/driftsky/p/4353549.html
Copyright © 2011-2022 走看看