Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, November 19, 2010

Faster and More Responsive Desktop in Linux

Faster Linux Desktop - Changing the scheduling paradigm to increase responsiveness for desktop useage



Came across an interesting article about speeding up the desktop usage in linux by altering the threading and process scheduling algorithm.

More details can be found here : http://blogs.computerworld.com/17371/the_linux_desktop_may_soon_be_a_lot_faster

My question is would this change performance for servers that have no graphical user interface running IE xorg? It looks like it won't!

Postgres unable to start with shmget. SHMMAX too small

Error Starting PostgreSQL, Could not create shared memory segment errors



If you have a large PostgreSQL configuration that supports many concurrent requests, you may find yourself starting it as you have increased the shared_buffers parameter or max_connections parameter, and it fails to start.

The error message will say something like could not create shared memory segment, Failed system call was shmget. This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter. You can either reduce the request size or reconfigure the kernel with larger SHMMAX. SHMMAX too small.

Here is the exact error message I got:


debian-testing:~# /etc/init.d/postgresql-8.3 start
Starting PostgreSQL 8.3 database server: mainThe PostgreSQL server failed to start. Please check the log output: 2010-11-17 13:53:34 EST FATAL: could not create shared memory segment: Invalid argument 2010-11-17 13:53:34 EST DETAIL: Failed system call was shmget(key=5432001, size=147382272, 03600). 2010-11-17 13:53:34 EST HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter. You can either reduce the request size or reconfigure the kernel with larger SHMMAX. To reduce the request size (currently 147382272 bytes), reduce PostgreSQL's shared_buffers parameter (currently 16384) and/or its max_connections parameter (currently 503). If the request size is already small, it's possible that it is less than your kernel's SHMMIN parameter, in which case raising the request size or reconfiguring SHMMIN is called for. The PostgreSQL documentation contains more information about shared memory configuration. failed!
failed!


PostgreSQL Debian increase SHMMAX



In order to increase the maximum amount of shared memory a linux program can access, we need to adjust kernel parameters. Since we are using Debian they are available in /etc/sysctl.conf. This should be similar for many linux distributions.

We simple edit this file:

sudo vim /etc/sysctl.conf


or if you have GNOME running

sudo gedit /etc/sysctl.conf


And either search for the line or add the line (most likely will have to add) :


kernel.shmmax = 147382272


Note the number here is the same as "size" in this system call, shown in my error message above: shmget(key=5432001, size=147382272, 03600)

Now we have to put these settings into effect by running the command


sysctl -p


And now we start PostgreSQL up without the error:


debian-testing:~# /etc/init.d/postgresql-8.3 start
Starting PostgreSQL 8.3 database server: main.
debian-testing:~#

Monday, September 13, 2010

Load Balancing Web Servers using ldirectord

Web Server Load Balancing



Summary



Using ldirectord to set up load balancing in apache, using debian linux as my distro, should also work on ubuntu or any other distro for that matter (bsd, red hat, etc). See below for links to the documentation. This setup is done using ldirectord's masq mode, which is basically ip masquerading function using iptables.

Let's Begin



Im just going to take a few mins to explain my load balancing set up. What we have is 1 router, the default gateway, connected to the internet, and also connecting to an internal network. Standard set up really.

What we want to do is set up load balancing with 2 (or more, our case we have 4) apache servers.

First step - download ldirectord



http://horms.net/projects/ldirectord/ (ldirectord) is a daemon that will route traffic to a certain host based on whatever load balancing algorithm you choose. Some examples of algorithms are round robin, where it selects the next host every time, or least connections, route to the host with the least number of open connections. There are a few other options that are covered in the ldirectord documentation (man page) and specifically for the algorithms is in the IPVSADM man page under -s (scheduler) located here (http://linux.die.net/man/8/ipvsadm)

Note that ldirectord is now a sub project of linux HA project called Heartbeat. It is available as a part of that package available here http://www.linux-ha.org/wiki/Main_Page

The reason for this is ldirectord is used as a part of that package. It is also useable on its own as I will show you.

Ldirectord set up



What we have to do next is set up ldirectord after we manage to get it compiled. Here is an example of a /etc/ha.d/ldirectord.cf:


# Global Directives
checktimeout=10
checkinterval=2
autoreload=no
logfile="local0"
quiescent=yes

# Virtual Server for HTTP
virtual=10.1.1.10:80
real=10.1.1.21:80 masq
real=10.1.1.22:80 masq
real=10.1.1.23:80 masq
real=10.1.1.12:80 masq
service=http
request="ldirectord.html"
receive="Test Page"
scheduler=wlc
protocol=tcp
checktype=negotiate


As you can see, we have set this ldirectord program up on the host located at 10.1.1.10 which is a physical machine. Using Heartbeat you can set up a virtual IP address and have 2 or more machines take over that address when the main one goes down, but that is for another article. We are strictly focusing on setting up ldirectord here.

Setting up the load balanced machines



On each of the load balanced machines (10.1.1.21, 22, 23, and 12) we need to set the default gateway to 10.1.1.10 (the ip address of the load balancer) Please adjust accordingly to your network. This can be done using the following command on debian linux and most other types

route add default gw 10.1.1.10


Next we have set up our ldirectord to check each machine by loading the page "ldirectord.html" shown above. So really it will be trying to access the page http://10.1.1.21/ldirectord.html. We have set up a regular expression as well above saying "Test Page". As long as this url returns this string somewhere, the host will be considered "up" by ldirectord. After we have set everything up, it should be good to go.

Running ldirectord



Please make sure your config file is in /etc/ha.d/ldirectord.cf because the script will be searching there for it. Next run ldirectord by typing

/usr/bin/perl /usr/sbin/ldirectord start


You should make a init.d script for this. After you have run ldirectord, typing

ipvsadm -L


should give you some information on its status.


s5:/etc/ha.d# ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP s5.np.local:www wlc
-> s4.np.local:www Masq 1 6 2245
-> s7.np.local:www Masq 1 5 2275
-> s3.np.local:www Masq 1 4 2563
-> s9.np.local:www Masq 1 6 2074


Here it shows that all hosts are up (their "Weight" is each 1) and have active connections running to them.

Setting up external routing



Now just have your router point all web traffic to 10.1.1.10:80 and you should have full load balancing. Note there are other problems such as how are you going to make sure they are all synchronized. You can use tools such as rsync, or use NFS to mount a share that contains all your files on each of the slave servers (our approach). The NFS approach seems to work nicely, however if you are hosting webservers for file transfers it may become a bottleneck so make sure your internet network is fast (1000 mbit) and tweaking NFS settings to your liking.

Thank you, your comments are welcome!

Monday, June 14, 2010

Facebook Chat in Empathy Ubuntu Linux

Using Facebook Chat in Ubuntu on Empathy


Facebook Chat Server Settings:


To set up the configuration:

Click edit->accounts, then click the Add button.


  • Account Type: Jabber

  • Reuse existing account

  • Create

  • Login ID: <username>@chat.facebook.com (Note you must create a facebook username if you have not already)

  • Under Advanced - Server: chat.facebook.com



Then you are finished. Make sure SSL is disabled (which should be the default). Please leave some comments! Thanks!

Saturday, April 10, 2010

Oblivion in Wine : Bypass Securom

Installing Oblivion under linux wine Ubuntu



Attempting to install oblivion in linux to run under wine causes some problems for me. The problem is securom, or saferom. When you attempt to install oblivion under wine (I am using Ubuntu) the installer fails. We need to find a method to bypass securom so we can use wine to play the game.

Since the install files are ultimately just tucked away inside some cab files, installation without using the actual installer is possible. All you have to do is use a tool called "Unsheild".

Users who are using playonlinux should still be able to use this guide, and install the game. Later use playonlinux to actually run the game.

What you will need to set up Oblivion



You will only need an open terminal and an ISO version of the disk. You could try this method with the DVD itself in the drive.

Mounting the ISO



I had to try this method in my attempt to install oblivion from some ISOs I had saved on my hard drive. What I ended up doing was mounting the ISO to my cdrom mount point:


sudo mount -o loop /path/to/oblivion.iso /media/cdrom


replacing /path/to/oblivion.iso with the path to the actual ISO file.

Setting up Unsheild



Then you need to install "Unsheild"


sudo apt-get install unsheild


Installing Oblivion



Then you run the command to "install" the game


unshield -d /path/to/install/to x /media/cdrom/data1.cab


replacing /path/to/install/to with the path you wish to install the game. This will extract all the cab contents to the specified folder.

Running the Game



Next we run the game


wine /path/to/install/to/Oblivion/OblivionLauncher.exe


Enjoy!

Wednesday, February 17, 2010

GLSL Shader Examples Vertex and Fragment

Hi Everyone,

Here is a quick example of a GLSL shader I use in my c++ 3d engine. Just thought I'd share some of the GLSL syntax with the internet community. I will fill in more information soon!

Vertex Shader


varying vec3 normal;

void main() {

normal = normalize(gl_NormalMatrix * gl_Normal);


//gl_Position = gl_ModelViewMatrix * gl_Vertex;

/*vec2 test = vec2((gl_MultiTexCoord0.xy - 0.5) * 2.0);
test.x *= 1.01;
test.y *= 1.01;
gl_Position.xy = test.xy;
gl_Position.z = 0.0;
gl_Position.w = 1.0;*/

gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}


Fragment Shader

uniform sampler2D texture_0;
uniform sampler2D texture_1;
varying vec3 normal;

void main() {
vec4 color = vec4(texture2D(texture_0, gl_TexCoord[0].xy));
float NdotL,NdotHV;
vec3 lDir = vec3(0.0, 0.0, 1.0);

if(color.r + color.g + color.b == 0.0)
color = vec4(1.0, 1.0, 1.0, 1.0);

if(color.r < 0.85)
color.r = 0.0;

color.g = color.r;
color.b = color.r;
//color.a = color.r;

vec3 n = normalize(normal);
NdotL = max(dot(n,lDir),0.0);
color.rgb *= NdotL;
gl_FragColor = color;
}

Thursday, February 11, 2010

Mass Effect 2 Runs in Wine in Ubuntu Linux

Mass Effect 2 using Linux in Wine



Get Wine



So I got mass effect 2 working in wine. Man is it a great game. To get it to work in wine:

go here and download wine (latest version as of now 1.1.38) http://sourceforge.net/projects/wine/files/Source/wine-1.1.38.tar.bz2/download

(note I would recommend 1.1.38 if you want to use the patches below)

extract and enter the directory in the terminal. Now we need to run the configure script:

./configure


Or to speed up compilation:

./configure --disable-tests


Which will skip compiling the wine test suite which generally you won't need.

Patching



Two patch files are located at:
http://bugs2.winehq.org/attachment.cgi?id=15638 for the mouse warping

http://bugs.winehq.org/attachment.cgi?id=26032 for crashes (I didnt seem to need this patch)

Next, you will need to apply some patches. There is one for crashing, and another to fix the mouse warping. I don't have these on hand at the moment. I couldn't get my mouse warping to work properly, so I edited mouse.c under dlls/dinput/ and made it so mouse button 3 would toggle mouse warp (on / off) which is a pain but makes the game more playable. To apply patches to a source, under the source tree, type:

#patch -p1 < NAMEOFPATCHFILE


Afterwards you can compile as shown below.

Compile


Ensure that you have XML support compiled in, as well as openal. You can determine this through the final output of the configure script. If you don't have the xml and openal dev packages, install them with your favourite package editor.


make
sudo make install


Again, an interesting way to speed up compilation on a multi core machine is to use:


make -j 4
sudo make install


You can replace "-j 4" with the number of processors you have (I have a quad core).

Finally



now run "winecfg" and set up a virtual desktop (I have to using nvidia latest binary driver geforce 9600).

Also, we need to install packages with winetricks to get this to work


wget http://www.kegel.com/wine/winetricks
sh winetricks d3dx9 d3dx10 vcrun2005 physx


Now run the installer, and finally run the game. I am able to play on full settings with 1900x1080 resolution :D

Enjoy!