PHP factor 30 performance difference from Linux to Windows

后端 未结 5 1499
不知归路
不知归路 2020-12-13 09:05

Our team is working is developing WordPress plugins and provides hosted instances on a couple of independent servers. Our WordPress installation is managed by Git, all serve

相关标签:
5条回答
  • 2020-12-13 09:45

    Use NGINX and FCGI for PHP via UNIX socket (not TCP socket).

    http://wiki.nginx.org/PHPFcgiExample

    You will notice immediately speed improvements even without accelerators. Additionally, above setup would have much lower memory usage footprint.

    0 讨论(0)
  • 2020-12-13 09:45

    To troubleshoot an issue of this kind, you'd have to:

    • Use system logs, namely error logs: sorting them by error level
      and/or date to identify dates of the issue.
    • Compare Windows updates in use on either system, one of them could be faulty.
    • Compare software in use on either system, the setup of one of these could be faulty.

    If that's the case, you'll want to uninstall the Windows update and/or the software that causes the issue, shutdown your server completely, then reinstall the update or software (to ensure a stable state during setup).

    Tools that can help you troubleshoot this issue include the sysinternals suite: http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx

    Or more simply, open source VBS scripts to produce comparable lists of updates and applications on a system.

    0 讨论(0)
  • 2020-12-13 09:48

    Windows has lots of services/policies that restrict, prevent, protect, control and etc usage of the computer in every situation.

    A good Microsoft certified specialist will be able to solve your question within minutes, because they will have the experience to tell exactly which settings/services/policies to check and disable/enable/change settings, so that the PHP scripts are executed faster.

    Out of my memory, I can only suggest you to check everything that deals with RAM, Hard Drive access, Environmental variables, Limits and Security (like Firewall). Everything that can affect the execution of php script, starting with some Remote Procedue Call policies and ending with the operating stack memory.

    The logic is that is php.exe calls some external .dll file to execute some operation, there might be checks on the way done by OS, that will slow both sending request via such .dll, and receiving the response from it. If the .dll uses hard drive to access something - hard drive access policies enter into the scene. Also, how everything is situated in the memory - in RAM or hard-drive cache of RAM. Application policies. Threads policies. Limits on max percentage available for use for applications.

    I am not saying that Windows-based hosts are bad, just that they are much more difficult to setup properly for a general admin. If you have Microsoft specialist on hands, he can tune your server to be as fast as Linux-based server.

    0 讨论(0)
  • 2020-12-13 09:49

    I took a look at that plugin on Github:

    https://github.com/wp-plugins/wp-slimstat

    And the offending file being included is a file that has been minified to some degree and really is data (not code), there are 5 variations each of which is about 400KB

    There is also that maxmind.dat file that is 400KB, although I don't know if it uses both.

    You are using an older version of the plugin, version 3.2.3 and there is a much newer one that may solve your problem.

    Comparing the differences is hard because the author or whoever has not kept the git history in order, so I had to manually diff the file. Most of the changes related to _get_browser seem to be adding a cache.

    It's possible loading that file is slow to parse, but I would expect PHP to be load both files at similar rates in both platforms granted that IO caching is working.

    EDIT Looking a bit closer that might not solve your problem. Those files are basically large Regular Expression lookup tables. Did your Linux system have an APC cache on it and this one does not? The APC cache would probably keep the PHP file data cached (although not the compiled regex patterns)

    0 讨论(0)
  • 2020-12-13 09:52
    • enable APC, when using PHP5.4

      • if you do not notice a speed gain, when APC is on, something is misconfigured

        [APC] extension=php_apc.dll apc.enabled=1 apc.shm_segments=1 apc.shm_size=128M apc.num_files_hint=7000 apc.user_entries_hint=4096 apc.ttl=7200 apc.user_ttl=7200

    • enable Zend Opcode when on PHP 5.5

      [Zend] zend_extension=ext/php_zend.dll zend_optimizerplus.enable=1 zend_optimizerplus.use_cwd=1 zend_optimizerplus.validate_timestamp=0 zend_optimizerplus.revalidate_freq=2
      zend_optimizerplus.revalidate_path=0 zend_optimizerplus.dups_fix=0 zend_optimizerplus.log_verbosity_level=1 zend_optimizerplus.memory_consumption=128 zend_optimizerplus.interned_strings_buffer=16 zend_optimizerplus.max_accelerated_files=2000 zend_optimizerplus.max_wasted_percentage=25 zend_optimizerplus.consistency_checks=0 zend_optimizerplus.force_restart_timeout=60 zend_optimizerplus.blacklist_filename= zend_optimizerplus.fast_shutdown=0 zend_optimizerplus.optimization_level=0xfffffbbf zend_optimizerplus.enable_slow_optimizations=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1

    • disable Wordpress extensions step-wise, to find the memory usage monster

    • set Wordpress: define('WP_MEMORY_LIMIT', '128M');, unless you use image converting plugins that should suffice
    • set unlimited memory in php.ini ini_set('memory_limit', -1);
    • profile without running Xdebug, this sounds crazy, but the debugger itself has a high impact
    • use memory_get_usage and spread calls all over the system to find the code position, where the memory leaks
    • give zend.enable_gc=1 a try, scripts will be slower, but use less memory
    • maybe just disable checking for the user browser in the SlimStats settings..
    • if that is not possible, try to override SlimStats getBrowser() function, with a faster getBrowser() substitute
    • for a speed comparison of user-agent fetchers, see https://github.com/quentin389/ua-speed-tests
    • https://github.com/garetjax/phpbrowscap
    0 讨论(0)
提交回复
热议问题