2015年9月4日金曜日

Install H2O with php-fpm

yonolatengo H2O......Go https://www.flickr.com/photos/yonolatengo/4905865998/in/photolist-8tvR3w-6wtbBX-6wxmgq-6wxkNu-6wt8vi-6wt7Dt-6wt6vH-6wt9Y8-bqokYN-2oyZAS-5kM5Pe-awZwAu-4QCzLp-6qKPtC-gr1GCZ-rDLrRB-5ng3vh-6L3UUo-2Tfcs-7XN2zL-bocyBY-5K1Ti5-4es3uw-e1ZPVx-4es2Ej-7oPMdP-7KX3qi-8W2EYo-8PADpe-8W2GdC-8VYBE4-8W2EhY-8W2DFL-8VYzae-8VYysX-8VYwu2-6wt73T-72ZuTT-8c3PzC-awWQzc-awWQ9P-25Eqqb-a3EUjj-6FjkA-oqu4AT-7GBs3i-4eo3UV-awWPs4-25EpAS-4eo4JP
https://h2o.examp1e.net/

H2O is known as HTTP(HTTP/2) Server of new era.
This is simple install log for H2O with php-fpm.

Build Environment:
Amazon Linux AMI 2015.03.1 (HVM), SSD Volume Type - ami-1c1b9f1c
c4.xlarge + EBS (General Purpose SSD) 100GB

Install some librarys
# yum -y groupinstall "Development Tools"
# yum -y install libyaml-devel openssl-devel httpd-tools php56-fpm
Install libuv
# cd /var/tmp
# git clone https://github.com/libuv/libuv.git
# cd libuv
# ./autogen.sh
# ./configure --prefix=/usr/local/libuv
# make -j 4
# make install
Install H2O
# cd /var/tmp
# git clone https://github.com/kazuho/h2o.git
# cd h2o/
# PKG_CONFIG_PATH=/usr/local/libuv/lib/pkgconfig/ cmake -DWITH_BUNDLED_SSL=on -DCMAKE_INSTALL_PREFIX=/usr/local/h2o .
# make -j 4
# make install
# ln -s /usr/local/h2o/bin/h2o /usr/bin/h2o
# h2o -v
h2o version 1.5.0alpha-1
OpenSSL: LibreSSL 2.2.2
Set config file for h2o with php-fpm
# emacs /etc/h2o.conf
pid-file: /var/run/h2o.pid
user: nobody
error-log: /var/log/h2o.error.log
access-log: /var/log/h2o.access.log
listen: 80

# php-fpm
file.custom-handler:
  extension: .php
  fastcgi.connect:
    host: 127.0.0.1
    port: 9000
    type: tcp

# Directory Index
file.index: [ 'index.php', 'index.html' ]

# Hosts
hosts:
  "localhost:80":
    paths:
      /:
        # www root
        file.dir: /var/h2o
        file.dirlisting: on

Make test php file
# mkdir /var/h2o/
# echo '<?php print 1;' > /var/h2o/index.php
Start H2O
# h2o -m daemon -c /etc/h2o.conf
Check
# curl -v http://localhost/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.40.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 04 Sep 2015 07:37:44 GMT
< Server: h2o/1.5.0alpha-1
< Connection: keep-alive
< x-powered-by: PHP/5.6.12
< content-type: text/html; charset=UTF-8
< transfer-encoding: chunked
<
* Connection #0 to host localhost left intact
1
Do Apache Bench
# ab -c 10 -n 10000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        h2o/1.5.0alpha-1
Server Hostname:        localhost
Server Port:            80

Document Path:          /
Document Length:        1 bytes

Concurrency Level:      10
Time taken for tests:   0.765 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1680000 bytes
HTML transferred:       10000 bytes
Requests per second:    13064.93 [#/sec] (mean)
Time per request:       0.765 [ms] (mean)
Time per request:       0.077 [ms] (mean, across all concurrent requests)
Transfer rate:          2143.46 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     0    1   0.4      1       4
Waiting:        0    1   0.4      0       4
Total:          0    1   0.4      1       4
ERROR: The median and mean for the waiting time are more than twice the standard
       deviation apart. These results are NOT reliable.

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      2
  99%      2
 100%      4 (longest request)
Stop H2O
# kill -TERM `cat /var/run/h2o.pid`