【问题标题】:Server benchmarking php performance服务器基准测试 php 性能
【发布时间】:2012-03-09 17:43:17
【问题描述】:

我有几个不同公司的托管帐户,我正在尝试评估哪个帐户可以最快地运行现有的 Wordpress 安装(无需先在每个帐户上安装 wordpress)。

我找到了一个 php 基准测试脚本来尝试确定哪个效果最好,但结果很奇怪。

<?php
/*
##########################################################################
#                      PHP Benchmark Performance Script                  #
#                         © 2010 Code24 BV                               # 
#                                                                        #
#  Author      : Alessandro Torrisi                                      #
#  Company     : Code24 BV, The Netherlands                              #
#  Date        : July 31, 2010                                           #
#  version     : 1.0                                                     #
#  License     : Creative Commons CC-BY license                          #
#  Website     : http://www.php-benchmark-script.com                     #  
#                                                                        #
##########################################################################
*/

    function test_Math($count = 140000) {
        $time_start = microtime(true);
        $mathFunctions = array("abs", "acos", "asin", "atan", "bindec", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt");
        foreach ($mathFunctions as $key => $function) {
            if (!function_exists($function)) unset($mathFunctions[$key]);
        }
        for ($i=0; $i < $count; $i++) {
            foreach ($mathFunctions as $function) {
                $r = call_user_func_array($function, array($i));
            }
        }
        return number_format(microtime(true) - $time_start, 3);
    }


    function test_StringManipulation($count = 130000) {
        $time_start = microtime(true);
        $stringFunctions = array("addslashes", "chunk_split", "metaphone", "strip_tags", "md5", "sha1", "strtoupper", "strtolower", "strrev", "strlen", "soundex", "ord");
        foreach ($stringFunctions as $key => $function) {
            if (!function_exists($function)) unset($stringFunctions[$key]);
        }
        $string = "the quick brown fox jumps over the lazy dog";
        for ($i=0; $i < $count; $i++) {
            foreach ($stringFunctions as $function) {
                $r = call_user_func_array($function, array($string));
            }
        }
        return number_format(microtime(true) - $time_start, 3);
    }


    function test_Loops($count = 19000000) {
        $time_start = microtime(true);
        for($i = 0; $i < $count; ++$i);
        $i = 0; while($i < $count) ++$i;
        return number_format(microtime(true) - $time_start, 3);
    }


    function test_IfElse($count = 9000000) {
        $time_start = microtime(true);
        for ($i=0; $i < $count; $i++) {
            if ($i == -1) {
            } elseif ($i == -2) {
            } else if ($i == -3) {
            }
        }
        return number_format(microtime(true) - $time_start, 3);
    }   


    $total = 0;
    $functions = get_defined_functions();
    $line = str_pad("-",38,"-");
    echo "<pre>$line\n|".str_pad("PHP BENCHMARK SCRIPT",36," ",STR_PAD_BOTH)."|\n$line\nStart : ".date("Y-m-d H:i:s")."\nServer : {$_SERVER['SERVER_NAME']}@{$_SERVER['SERVER_ADDR']}\nPHP version : ".PHP_VERSION."\nPlatform : ".PHP_OS. "\n$line\n";
    foreach ($functions['user'] as $user) {
        if (preg_match('/^test_/', $user)) {
            $total += $result = $user();
            echo str_pad($user, 25) . " : " . $result ." sec.\n";
        }
    }
    echo str_pad("-", 38, "-") . "\n" . str_pad("Total time:", 25) . " : " . $total ." sec.</pre>";

?>

现在在一台服务器上,我得到的平均时间约为 10 秒,在另外 15 台服务器上(到目前为止还不错),但在第三台服务器上,平均大约是 45 秒。这很奇怪,因为该服务器有一个运行得非常快的有效 Wordpress 安装(大约 1.5 秒的页面加载时间)。

我的问题是,为什么这台服务器会显示这么高的结果,但似乎工作正常?其次,这是否意味着这不是确定哪个主机最终会以最快的速度运行 Wordpress(所有其他条件相同)的好方法?如果这不是一个好方法,您有什么建议吗?

【问题讨论】:

    标签: php wordpress benchmarking


    【解决方案1】:

    你需要实际安装 wordpress 才能确定。

    我将只编辑每个和require this file 的 index.php 文件。

    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    require('benchmark.php');
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require('./wp-blog-header.php');
    

    我已经进行了一段时间的基准测试,这将为您提供有关当前内存使用情况和服务器处理速度的良好信息。你甚至可以用httperf 打服务器几百次以获得真正的服务器能力。

    【讨论】:

      【解决方案2】:

      你必须安装 wordpress 才能分析每一个的性能。事实上,你应该在这三个中都安装了完整的 wordpress 环境,我的意思是,应该安装所有的 wordpress 插件,因为它们会对性能产生很大的影响。此外,apache、mysql 和 php 在所有三台服务器中都应进行相同的调整。

      一旦你这样做了,你就可以使用 jMeter (http://jmeter.apache.org/) 来真正测试你的服务器,看看你的服务器可以处理多少请求。

      【讨论】:

        猜你喜欢
        • 2017-05-29
        • 2014-07-30
        • 2014-12-19
        • 2020-09-27
        • 1970-01-01
        • 2013-08-22
        • 1970-01-01
        • 1970-01-01
        • 2010-09-14
        相关资源
        最近更新 更多