Tag Archives: cluster

Membuat Cluster HPA (High Performance + Availability) dengan RaspberryPi

Standard

English version : click here

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 😀

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
loghost    local0 info
maxconn 4096
/usr/share/haproxy
user haproxy
group haproxy
daemon

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

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

Membuat Cluster RapsberryPi dengan OpenMPI

Standard

English version : click here

RaspberryPi versi 2 kini sudah cukup powerful. Quad-core 900 MHz, 1 GB RAM, dan bisa berjalan dengan power supply 1A 5V saja. Maka saya membeli 4 buah RaspberryPi (RPI) ini, dan membuat cluster berbasis OpenMPI : http://www.open-mpi.org/. Di luar dugaan saya, ternyata ini mudah sekali dilakukan 🙂

Nampaknya sudah tiba saatnya dimana kita bisa memanfaatkan RaspberryPi, dan komputer hemat energi lainnya, sebagai server. Dan lalu dimanfaatkan seperti superkomputer, dengan membuat cluster dari komputer-komputer ini. 🙂 (y)

Sekilas tentang OpenMPI, software ini bisa dipergunakan oleh software lainnya untuk menyebarkan beban kerjanya ke banyak komputer. Jadi, OpenMPI bertindak sebagai semacam koordinator. Dalam riset ini, saya akan menggunakan OpenMPI untuk menyebarkan beban kerja kompresi, yaitu dari software mpibzip2.

Silakan ikuti panduan berikut ini :


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

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

# Standard tools
apt-get install screen mosh telnet htop iftop ethtool
# OpenMPI related
apt-get install openmpi-bin build-essential libbz2-dev libopenmpi-dev ssfs
# create SSH keys,
# then copy GreenPi-1’s key to all /root/.ssh/authorized_keys
# and all GreenPi keys to GreenPi-1 /root/.ssh/authorized_keys
ssh-keygen -t rsa -b 4096

# some preparations
mkdir /tmp1
export http_proxy=”http://192.168.1.10:3128/&#8221;

# Install OpenMPI
cd /tmp
wget http://compression.ca/mpibzip2/mpibzip2-0.6.tar.gz
tar xzvf mpibzip2-0.6.tar.gz
cd mpibzip2-0.6
# Need to edit Makefile
vi Makefile
## make sure the line with CC=c++ is changed into
# CC=mpic++
# Otherwise, we’ll get the following error message :
# mpibzip2.cpp:72:17: fatal error: mpi.h: No such file or directory

make
make install

#==========
#EXECUTE ON GreenPi-1

# Prepare the logfile to be compressed
mkdir /tmp1
cp /var/log/syslog /tmp1/

### Now do SSH from slaves to GreenPi-1 / 192.168.1.171,
### and say “yes” when asked to save its RSA fingerprint

### Then, do SSH from GreenPi-1 to all slaves,
### and say “yes” when asked to save its RSA fingerprint

# Then you can do the following,
# create SSHFS mount to GreenPi-1 on all slaves
ssh root@192.168.1.172 sshfs root@192.168.1.171:/tmp1//tmp1
ssh root@192.168.1.173 sshfs root@192.168.1.171:/tmp1//tmp1
ssh root@192.168.1.174 sshfs root@192.168.1.171:/tmp1//tmp1

### Test OpenMPI locally
### Yes, OpenMPI can be run on a single computer too,
### very handy for testing purposes
mpirun -v -n 4 mpibzip2 /tmp1/syslog

### Put all slaves IP address
echo “192.168.1.172” >> /etc/openmpi/openmpi-default-hostfile
echo “192.168.1.173” >> /etc/openmpi/openmpi-default-hostfile
echo “192.168.1.174” >> /etc/openmpi/openmpi-default-hostfile

###  Run mpibzip2 on ALL slaves
mpirun -v -n 16 –hostfile /etc/openmpi/openmpi-default-hostfile /usr/bin/mpibzip2 -v  /tmp1/syslog

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

Ini hasil yang saya dapatkan :
RaspberryPi 4-core = 643 detik
RaspberryPi 16-core = 163 detik

Penambahan kecepatannya nyaris linear 🙂 4x lipat lebih cepat. Bagus sekali.

Demikian, saya akan lanjutkan lagi dengan berbagai cara lainnya untuk memanfaatkan cluster RaspberryPi ini 🙂
Semoga bermanfaat.