Sunday, June 23, 2013

Optimize the OS to handle large number of concurrent requests

Theoretically Node.js can handle huge number of concurrent requests without blocking the application. This means server created using Node.js can handle concurrent requests without any problem unlike thread based server applications such as Apache servers.
I had to create a server application using Node.js to handle high level of concurrent requests. During the testing for higher level of concurrency one error I got was connect EMFILE . 
This error means that the OS is not allowing your program to open more files or sockets. So to handle higher levels of requests, you need to optimize the OS. We can do this by changeing the maximum number of files that can be open. To check the current limit in Linux system type
ulimit -n
For a Linux based system, this can be done using following instructions
One method is reset the limit for your current shell. This can be done easily by typing ulimit -n 4096. 4096 is the new maximum limit
The other way is by editing /etc/security/limits.conf file. open it using your favorite editor.
sudo gedit /etc/security/limits.conf
Add following two lines before the end of file
* soft nofile 4096
* hard nofile 65535
soft limit is the current value. Hard limit is the maximum limit. The soft value cannot exceed the hard value.Then logout and re login to your system. you can check the limit by  ulimit -n

Wednesday, May 1, 2013

Set up your Raspberry Pi

Have you ever used this cool piece of hardware called ‘Raspberry Pi’. If not your should try it out. It is cheap credit-card-sized computer. You can google it for more info.
Raspberry Pi
I recently acquired one of this for my final year project work. I went straight away to set this up. I read many number of posts to figure out how to do this. If you do not like to read lengthy posts, then this is the place. I will try to keep things simple.
You need to have a SD card (probably 2GB minimum ), power supply (5V , around 700mA) , a USB key board and a RCA cable. There is a HDMI port which can be used to take the video out as well. If you do not have a RCA cable and a USB key board with you (I didn’t) you can still use this using a network cable. More on that later. If you cannot find a power source for this but you have a USB-to-microUSB cable (normally comes with android devices) you can power up by plugging it to the USB port. 
Download the OS
you can download the OS from http://www.raspberrypi.org/downloads . if you are planning to install JVM, then you should use the ‘Soft-float Debian “wheezy”‘ version. If not the Raspbian version is enough for any beginner. (At the time of writing thisOracle released a Developer Preview of JDK 8 runtime for Linux ARM hardfloat and with JavaFX which supports the Raspbian version).
Install the OS
Format the SD card. if you are using windows or Mac you can use SD Card Association’s SD Formatter to do it easily. Then download the OS and extract it and use Win32DiskImager (Windows users) or dd (for Unix) to write the image to the SD card.
That’s it. Power up the Raspberry Pi (no power switch to switch it on. just connect the power.).  When you start for the first time, you will get a window to configure the system. you can just skip this or access this late by typing sudo raspi-config . When you exit the configuration. you will be asked to enter user name and password.
Default login :  Username: pi     Password: raspberry
You can work on the terminal or can access the GUI by typing startx. 
Configure 
config
There are some configurations you might need to do. You can read more about the configuration from here. Some of them are
  • expand_rootfs – If you are using a SD card larger than 2GB, you should do this. this expands the initial image to fill the unused parts in the SD card
  • change_pass –  change the password
  • memory_split – This can be used to configure how much memory to share for GPU. If you are not using much video processing, you can reduce this to a minimum value.