Google
 

Saturday, December 25, 2010

Load Balancing LTSP clients using Ethernet Bridging

Typical LTSP setup has the following configuration:


+-------------+
| Server |
+-------------+
| eth0 | eth1 |
+------+------+
/ |
/ |
Internet Switch
|
+---------+-------------+
| | |
Client-1 Client-2 ... Client-n

LTSP Clients

The problem with this is that the network card bottlenecks the performance. Once the number of clients increases (usually >5), even though the server is capable of handling the load, the network card (usually, 100BASE-TX) can't provide the throughput.

There are two solutions to this:
1. Use 1000BASE-T (gigabit) ethernet cards and switches
2. Use load balancing

Using gigabit ethernet cards solves the problem but they are expensive. The switches are expensive too. Plus there are flow control problems if the clients have 100Base-TX cards, which is usually the case.

Load balancing is an easier and cheaper approach. Although this can also go fairly complicated, here i'm going for the simplest one using ethernet bridging.

The trick is to use multiple NICs connected to multiple switches. Then bridge the cards to provide a common interface. Here's what it looks like:

+--------------------+
| Server |
+------------------- +
| eth0 | eth1 = eth2 |
+------+------+------+
/ | |
/ | |
Internet Switch Switch
| |
+----+-------+ +----+-------+
| | | | | |
C-1 C-2 ... C-n C-1 C-2 ... C-n

LTSP Clients LTSP Clients

Lets say, there are three NICs: eth0, eth1 and eth2. eth0 is connected to internet. eth1 (say, 192.168.0.254) is connected to LTSP clients. eth2 is unused and is supposed to be bridged with eth1.

First install bridge-utils
# apt-get install bridge-utils
Create a bridge (br0) and add eth1 and eth2 to it
# brctl addbr br0
# brctl stp br0 off
# brctl addif br0 eth1
# brctl addif br0 eth2
Now release the IP addresses of eth1 and eth2
# ifconfig eth1 down
# ifconfig eth2 down
# ifconfig eth1 0.0.0.0 up
# ifconfig eth2 0.0.0.0 up
Assign the LTSP IP address to bridge.
# ifconfig br0 192.168.0.254 up
Now connect eth1 and eth2 to separate switches, and each switch to (equal number of) LTSP clients.

Tuesday, December 21, 2010

Tiny Issue Tracker

I find most issue trackers bloated for most of my requirements. I usually need a simple issue tracker to communicate between couple of persons but most issue trackers available have plethora of features, usually with full blown database.

So here's my solution: Tiny Issue Tracker. A PHP/SQLite based, single-file issue tracker.
Source: https://github.com/jwalanta/tit


Features

- Super Lightweight (currently ~17KB, ~500 lines of code)
- Multi-user
- Email Notifications
- Auto DB creation on first run
- Issue Priority (High, Medium, Low)
- Comment on issues
- Throw and run!

Installation is as simple as it can get:
- Modify configurations in the file (tit.php)
- Upload to webserver (rename if necessary) & load from browser

Demo
http://diyaalo.com/tit
username, password = demo, demo123
Check email notifications at http://demo123.mailinator.com/

PS: The acronym is a complete coincidence though :P

Tuesday, December 14, 2010

HackJatra v0.1

Jitendra started the discussion, but i wouldn't be wrong if i say we all had the itch. A hackathon was in everybody's mind since quite a while. So we started a email discussion among fellow hackers, mostly Pulchowk Campus BCT'ians. We had few projects in mind - ATM Locator, Khanchuwa and Online Nepali Donation system. All we needed was a date for the event. But before we could finalize that, we coined a term for the event.

HackJatra. For non-Nepalis out there, Jatra means festivity. Later the term was also informally understood as "Hack by day, Jatra by night" :P. More on that later..

Finally, we fixed the date and venue: 11th December, 2010 at IT Park Banepa, starting from 9am.


The project we did were:

1. ATM Locator
Map enabled app to list and search ATMs in Nepal.
Team: Abhinav Singh, Bibek Shrestha, Jitendra Harlalka, Subodh Satyal, Sushil Shilpakar

2. Khanchuwa
Community based delicacies listing portal. The idea was discussed at BarCamp Kathmandu 2010.
Team: Jwalanta Shrestha, Abhishek Singh

3. Tweet NEA
Automated twitter accounts to tweet the loadshedding schedule.
Team: Manish Modi, Suraj Sapkota

More on the projects in the wiki.

Needless to say, the event was extremely fun. The joy of hacking for fun with extremely talented fellow hackers is indescribable. The projects we started are almost done; few more hours of collaborations and they'll all be ready to launch.


Future plans:
1. Do some branding of HackJatra; create a logo, have a website and make the projects more accessible and sharable.
2. Encourage other teams to do similar HackJatras
3. Do another HackJatra ASAP

O BTW, we even had booze party by night (Jatra :P)

Friday, November 12, 2010

Generating Tag Cloud the Unix way

UPDATE: I've modified the script to add color and transparency :)

Ushaft's this tweet on creating tag cloud caught my attention. While there are better tools available online, i decided to give it a try in Linux :)

First we need to generate a frequency list of words out of a file. No brainer. I used the GNU/GPL license as source text.

cat /usr/share/common-licenses/GPL |
tr 'A-Z' 'a-z' |
sed 's/[^a-z ]//g' |
sed 's/\s/\n/g' |
awk '{if (length($1)>=3) print $1 }' |
sort | uniq -c | sort -nr > freq.txt

Explanation (per line):
1. Print the license
2. Convert to lowercase
3. Remove punctuations
4. One word per line
5. Discard words with 2 or less long
6. Grab frequency and write to freq.txt

freq.txt needs some editing to remove irrelevant words like "the", "but", etc.

Now to create tag cloud, i wrote a simple awk script that outputs svg file. Saved this as gentagcloud.awk (Please change the width, height and scale variable to your taste)

#!/bin/awk -f

BEGIN {
WIDTH=1000
HEIGHT=600
SCALE=1

OFS=""

print "<?xml version=\"1.0\"
encoding=\"UTF-8\" standalone=\"no\"?>"
print "<svg width=\"",WIDTH,"\" height=\"",
HEIGHT,"\" version=\"1.1\"
xmlns=\"http://www.w3.org/2000/svg\">"
}

{
R = int(rand()*9)
G = int(rand()*9)
B = int(rand()*9)

print "<text style=\"fill:#",R,G,B,";opacity:0.75;
font-size:",$1*SCALE,"px;\"
x=\"",rand()*(WIDTH-100),"\"
y=\"",rand()*HEIGHT,"\">",$2,"</text>"
}

END{ print "</svg>" }

Now to create tag cloud,

awk -f gentagcloud.awk < freq.txt > tagcloud.svg

Tada! Tag cloud generated, view tagcloud.svg in your browser or image viewer

If you have ImageMagick installed, you can convert it directly to png too. (Transparency isnt handled properly. If you have workarounds, please comment)

awk -f gentagcloud.awk < freq.txt | convert - tagcloud.png

BTW, the tag cloud was like this: (lil' ugly, but WTH :))

Thursday, February 25, 2010

Internet Connection Sharing in Linux over Ad-hoc Wireless

Laptops are common these days and so is wireless networking that comes with it. Almost all of us use Wireless Router for wireless networking and internet sharing. But most of us might not be familiar with ad-hoc mode that works in every wireless card and can eliminate the use of router altogether. Here's how:

To setup ad-hoc wireless, you basically set two or more wireless cards to same ESSID in ad-hoc mode and different IP addresses.

Setting the wireless card in ad-hoc mode

Generally iwconfig is used to set the wireless mode, but if you have madwifi drivers (see this too), the commands are slightly different. Go to terminal and type,

iwconfig
If you see interfaces named wlan0, wlan1, etc iwconfig will work. If you see interface names similar to ath1 and wifi0, then madwifi specific commands are to be used.

For general wifi cards:
sudo iwconfig wlan0 mode ad-hoc
Replace wlan0 with the interface name as listed by iwconfig

For cards using madwifi driver:
sudo wlanconfig ath1 destroy
sudo wlanconfig ath1 create wlandev wifi0 wlanmode adhoc
Now set essid. Pick some name like 'adhocwifi'
sudo iwconfig wlan0 essid adhocwifi
If required, to set encryption key
sudo iwconfig wlan0 key 1234567890
Now set IP address:
sudo ifconfig wlan0 192.168.0.1
Follow the above steps for another wireless card and set IP address in same subnet, say 192.168.0.2, and ping each other.

The whole ad-hoc mode setting can also be done using GUI network-manager, but since i'm not so much fond of graphical interface i'm not covering it. It should be simple.. :)

Internet Connection Sharing

Now to share the internet over wireless,
sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
where ppp0 is the connection you want to share (PPPoE connection in this case)

You also need to enable IP forwarding:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Or, to enable permanently add the following line to /etc/sysctl.conf
net.ipv4.ip_forward=1
Some ISPs might limit the TTL so that you wont be able to share the internet. Fix:
sudo iptables -t mangle -A PREROUTING -j TTL --ttl-inc 1

Using the shared internet (in Linux)

Now to use the shared internet on another computer, set it to ad-hoc mode and assign IP address in the same subnet as described above and perform the following:

1. Set the IP of computer sharing internet as gateway
sudo route add default gw 192.168.0.1
2. Set DNS server. We're using Google's DNS.
sudo sh -c "echo 'nameserver 8.8.8.8' >> /etc/resolv.conf"
You can also use IP and DNS Masquerading to ease the task.


Using the shared internet (in M$ Windows)

If you want to use the shared internet on M$ Windows,

1. Connect to the Wireless Network (in this case 'adhocwifi')
2. Go to Network Connections
3. Right click the Wireless Connection
4. Select the Internet Protocol (TCP/IP) and click Properties
5. Set IP to 192.168.0.2 (or accordingly in the same subnet as set on Linux box), gateway to 192.168.0.1 (as set on Linux box) and DNS to 8.8.8.8