.htaccess mod_rewrite performance

后端 未结 2 1038
终归单人心
终归单人心 2020-12-15 22:23

i searched a lot on SOF about .htaccess and mod_rewrite and i want to performance wise which one is faster:

RewriteRule ^([a-z0-9]+)/?$ index.php?id=$1 [NC,L         


        
2条回答
  •  自闭症患者
    2020-12-15 22:55

    When in doubt, test it out. I setup a test server running Ubuntu 2011.10 with Apache2 and used the siege load testing app to perform 3 tests. The test ran for 1 minute (or until 5000 failures) with 50 concurrent users requesting '/index.html'

    Test #1 used the following rewrite rule configuration:

    RewriteEngine on
    RewriteRule ^([a-z0-9]+)/?$ /index.html?id=$1 [NC,L]
    

    The results from siege:

    Transactions:                 300970 hits
    Availability:                  98.36 %
    Elapsed time:                  57.25 secs
    Data transferred:              20.38 MB
    Response time:                  0.00 secs
    Transaction rate:            5257.12 trans/sec
    Throughput:                     0.36 MB/sec
    Concurrency:                    9.04
    Successful transactions:      300970
    Failed transactions:            5009
    Longest transaction:            0.02
    Shortest transaction:           0.00
    

    Test #2 with a rewrite rule configuration:

    RewriteEngine on
    RewriteRule ^(.*)/?$ /index.html?id=$1 [NC,L]
    

    The results:

    Transactions:                 225244 hits
    Availability:                  97.82 %
    Elapsed time:                  42.43 secs
    Data transferred:              15.25 MB
    Response time:                  0.00 secs
    Transaction rate:            5308.60 trans/sec
    Throughput:                     0.36 MB/sec
    Concurrency:                    8.71
    Successful transactions:      225244
    Failed transactions:            5009
    Longest transaction:            0.18
    Shortest transaction:           0.00
    

    Test #3 with the following rewrite rule:

    RewriteEngine on
    RewriteRule ^([^/]*)/?$ /index.html?id=$1 [NC,L]
    

    The results:

    Transactions:                 210469 hits
    Availability:                  97.68 %
    Elapsed time:                  39.39 secs
    Data transferred:              14.25 MB
    Response time:                  0.00 secs
    Transaction rate:            5343.21 trans/sec
    Throughput:                     0.36 MB/sec
    Concurrency:                    8.60
    Successful transactions:      210469
    Failed transactions:            5009
    Longest transaction:            0.02
    Shortest transaction:           0.00
    

提交回复
热议问题