Tag Archives: log

GreenICT : Membuat Cluster HPA (High Performance + Availability) dengan RaspberryPi….

GreenICT : Membuat Cluster HPA (High Performance + Availability) dengan RaspberryPi. :: Infrastruktur IT yang ideal adalah yang performanya tinggi (high performance), dan selalu bisa diakses (high availability, resilient). Dulu, ini cuma bisa menjadi kenyataan dengan membeli perangkat keras yang mahal, dan software pendukungnya yang kadang malah lebih mahal lagi. Kini, kita bisa membangunnya dengan menggunakan RaspberryPi 🙂 Hemat energi, performa tinggi, hemat space / tempat, hemat harga juga.

Infrastruktur web berbasis Cluster HPA di RaspberryPi terdiri dari :

# Load-balancer (HAproxy) : port 80 : berfungsi mengatur distribusi beban kerja, agar merata ke semua Edge server yang ada. Juga mendeteksi server yang down, dan otomatis tidak menyertakannya dalam distribusi kerja.

# keepalived : mendeteksi jika ada load-balancer yang down, lalu otomatis mengalihkan ke load-balancer lainnya.

# Edge server (Varnish) : port 6081 : melayani sebanyak mungkin request yang masuk, agar tidak membebani Webserver. Membantu memberikan waktu respons yang tercepat.

# Webserver (Apache + PHP) : port 6080 : melayani request yang masuk dari Varnish dengan secepat mungkin.

# Database (MySQL) : menyimpan data yang dibutuhkan oleh web-apps.

Untuk membangunnya, silakan ikuti panduan terlampir.

Dengan menghidup / matikan Varnish, maka kita bisa mengatur berapa jumlah RaspberryPi yang akan ikut serta dalam benchmark. 

Terlampir adalah hasil benchmark yang saya lakukan :

1 x RaspberryPi = 760 hits/detik
2 x RaspberryPi = 1100 hits/detik
3 x RaspberryPi = 1250 hits/detik
4 x RaspberryPi = 1260 hits/detik

Ternyata, RaspberryPi bisa melayani sampai ratusan hits/detik 🙂
Luar biasa untuk sebuah komputer yang hanya menggunakan daya sebesar 5 watt 🙂 (y) 🙂

Namun, ada yang aneh….. hasil benchmark seperti tertahan di kisaran 1200 hits/detik. Tidak bisa lebih lagi dari itu, walaupun jumlah RaspberryPi yang disertakan di benchmark terus ditambah. Kenapa ini ? 🙂

Setelah saya investigasi selama beberapa waktu…..ternyata, laptop saya, yang melakukan benchmark ke Cluster HPA ini, koneksi LAN nya hanya 100 Mbps :D 

Alhasil, cukup 2 RaspberryPi saja sudah sukses menghabiskan seluruh bandwidth 100 Mbps yang ada tersebut 😉 oalah, he he

Jadi, saya akan beli nanti perangkat LAN dengan bandwidth 1 Gbps, dan mengulang lagi benchmark ini. 
Penasaran juga ya…. 🙂

==================
CATATAN

Pada saat ini ada satu kelemahan RaspberryPi 2, yaitu tidak mampu melayani kecepatan akses yang mencapai ribuan session per detik. Maksimum hanya sekitar 800 session/detik.

Bottleneck ini saya temukan ketika bingung karena HAproxy mentok performanya di sekitar 800 session/detik saja. Nyaris tidak berbeda dengan performa Varnish.

Ketika saya teliti, ternyata ada proses bernama ksoftirqd, yang menggunakan 100% CPU #1. 
ksoftirqd menjadi overload begini ternyata karena terlalu deras interrupt dari port network… saya temukan ini dengan melihat isi /proc/interrupt

Alhasil, benchmark diatas saya lakukan dengan HAproxy yang berada di komputer lainnya. Sehingga, seluruh kapasitas pemrosesan network di RaspberryPi bisa dimanfaatkan oleh Varnish (tidak terbagi dengan HAproxy)

Jadi, untuk saat ini, RaspberryPi belum cocok digunakan sebagai load-balancer dengan traffic yang sangat tinggi. 

Demikian, semoga bermanfaat 🙂

# =====================
# EXECUTE ON ALL RPI

### config
# GreenPi-1 = 192.168.1.171  
# GreenPi-2 = 192.168.1.172 
# GreenPi-3 = 192.168.1.173 
# GreenPi-4 = 192.168.1.174 

# Install all the software : Apache, MySQL, PHP, Varnish, HAproxy, keepalived; total approx. 150 MB
apt-get install phpmyadmin mysql-server haproxy screen telnet htop iftop keepalived

# Varnish on Debian wheezy (7.x) is too old & buggy (3.0.2, child process kept dying), 
# we'll need to install straight from source
apt-get install automake libtool python-docutils libpcre++-dev libncurses5-dev libreadline-dev
wget http://repo.varnish-cache.org/debian/pool/varnish-4.0/v/varnish/varnish_4.0.3.orig.tar.gz
tar xzvf varnish_4.0.3.orig.tar.gz
cd varnish-4.0.3
sh autogen.sh
sh configure
make
make install
useradd varnishd
ldconfig -n /usr/local/lib/

# ========
# Varnish config file : /etc/varnish/default.vcl
vcl 4.0;
backend default {
    .host = "127.0.0.1";
    .port = "6080";

# ========
# Varnish init script : /etc/init.d/varnish

DAEMON=/usr/local/sbin/varnishd

==============================

# Restart Varnish
/etc/init.d/varnish restart

# ========
# Apache config file : /etc/apache2/ports.conf

# run apache on port 6080
NameVirtualHost *:6080
Listen 6080

# ========
# Apache config file : /etc/apache2/sites-enabled/000-default

<VirtualHost *:6080>

# ========
# PHP5 config file : /etc/php5/apache2/php.ini

session.cache_limiter = public

==============================

# Restart Apache
/etc/init.d/apache2 restart

# Let's use WordPress as the web-app, just to make thing simple in this example
cd /var/www
wget https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
cp wordpress/wp-config-sample.php wordpress/wp-config.php
# edit wordpress' config file
vi wordpress/wp-config.php

# disable forced redirect to port 80
vi wp-content/themes/twentyfifteen/functions.php
# then put this on the 2nd line :
#      remove_filter('template_redirect','redirect_canonical');

# then open http://GreenPi-1/wordpress/ to finish WordPress setup

# ========
# HAproxy default file : /etc/default/haproxy

ENABLED=1

# ========
# HAproxy config file : /etc/haproxy/haproxy.cfg

global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        #log loghost    local0 info
        maxconn 4096
        #chroot /usr/share/haproxy
        user haproxy
        group haproxy
        daemon
        #debug
        #quiet
nbproc 2

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen  GreenPies 192.168.1.170:80
        cookie  SERVERID rewrite
        balance roundrobin
        server  web1 192.168.1.171:6081 cookie app1inst1 check inter 2000 rise 2 fall 5
        server  web2 192.168.1.172:6081 cookie app1inst2 check inter 2000 rise 2 fall 5
        server  web3 192.168.1.173:6081 cookie app1inst3 check inter 2000 rise 2 fall 5
        server  web4 192.168.1.174:6081 cookie app1inst4 check inter 2000 rise 2 fall 5

listen  stats   192.168.1.170:81
        mode            http
        log             global

        maxconn 10

        clitimeout      100s
        srvtimeout      100s
        contimeout      100s
        timeout queue   100s

        stats enable
        stats hide-version
        stats refresh 30s
        stats show-node
        stats auth admin:password
        stats uri  /haproxy?stats

# ===========================
# Create a Virtual IP address on ALL RPI,
# for HAproxy to listen to 

ifconfig eth0:0 192.168.1.170 netmask 255.255.255.0 up
echo "net.ipv4.ip_nonlocal_bind=1" >> /etc/sysctl.conf 
sysctl -p

# ========
# keepalived config file : /etc/keepalived/keepalived.conf

vrrp_script chk_haproxy {           
        script "killall -0 haproxy"     # cheaper than pidof
        interval 2                      # check every 2 seconds
        weight 2                        # add 2 points of priority if OK
}

vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 101                   # same priority for all nodes
        virtual_ipaddress {
            192.168.1.170
        }
        track_script {
            chk_haproxy
        }
}

# ======================

# ===========================
# Make all the changes effective

a2enmod expires
/etc/init.d/apache2 restart
/etc/init.d/varnish restart
/etc/init.d/haproxy restart

# ================
# Let's benchmark !

ab -c 100 -n 20000 http://192.168.1.170/wordpress/

# HAproxy stats available on http://192.168.1.170:81/haproxy?stats

# =====================================

Post imported by Google+Blog for WordPress.