Apache Server Vs TomCat

Apache server is a web server. Tomcat is a servlet container where servlet container is compiled , executable program. Browser connects to Apache, whether Tomcat contain what are connect from Apache to process. However, tomcat now includes a web server so you can cut out the middle man. You would not want to do this on a large environment process to produce you production. Here container work as a intermediary between web server and servlet in the servlet container.

When a request arrives, the container points the request to a servlet and passes request to produce response by translating into C++ objects. The container translates the response into the network format and send it back to the Web server.

Advertisements

Strace – A very powerful troubleshooting tool

Many times I have come across seemingly hopeless situations where a program when compiled and installed in GNU/Linux just fails to run. In such situations after I have tried every trick in the book like searching on the net and posting questions to Linux forums, and still failed to resolve the problem, I turn to the last resort which is trace the output of the misbehaving program. Tracing the output of a program throws up a lot of data which is not usually available when the program is run normally. And in many instances, sifting through this volume of data has proved fruitful in pin pointing the cause of error.
For tracing the system calls of a program, we have a very good tool in strace. What is unique about strace is that, when it is run in conjunction with a program, it outputs all the calls made to the kernel by the program. In many cases, a program may fail because it is unable to open a file or because of insufficient memory. And tracing the output of the program will clearly show the cause of either problem.

The use of strace is quite simple and takes the following form:

$ strace <name of the program>

For example, I can run a trace on ‘ls’ as follows :

$ strace ls

And this will output a great amount of data on to the screen. If it is hard to keep track of the scrolling mass of data, then there is an option to write the output of strace to a file instead which is done using the -o option. For example,

$ strace -o strace_ls_output.txt ls
… will write all the tracing output of ‘ls’ to the ‘strace_ls_output.txt’ file. Now all it requires is to open the file in a text editor and analyze the output to get the necessary clues.
It is common to find a lot of system function calls in the strace output. The most common of them being open(),write(),read(),close() and so on. But the function calls are not limited to these four as you will find many others too.
For example, if you look in the strace output of ls, you will find the following line:
open("/lib/libselinux.so.1", O_RDONLY)  = 3
This means that some aspect of ls requires the library module libselinux.so.1 to be present in the /lib folder. And if the library is missing or in a different path, then that aspect of ls which depends on this library will fail to function. The line of code signifies that the opening of the library libselinux.so.1 is successful.

Here I will share my experience in using strace to solve a particular problem I faced. I had installed all the multimedia codecs including the libdvdcss which allowed me to play encrypted DVDs in Ubuntu Linux which I use on a daily basis. But after installing all the necessary codecs, when I tried playing a DVD movie, totem gave me an error saying that it was unable to play the movie (see the picture below). But since I knew that I had already installed libdvdcss on my machine, I was at a loss what to do.

Fig: Totem showing error saying that it cannot find libdvdcss

Then I ran strace on totem as follows :

$ strace -o strace.totem totem
… and then opened the file strace.totem in a text editor and searched for the string libdvdcss . And not surprisingly I came across this line of output as shown in the listing below.
# Output of strace on totem
open("/etc/ld.so.cache", O_RDONLY)      = 26
fstat64(26, {st_mode=S_IFREG|0644, st_size=58317, ...}) = 0
old_mmap(NULL, 58317, PROT_READ, MAP_PRIVATE, 26, 0) = 0xb645e000
close(26)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
...
open("/lib/tls/i686/cmov/libdvdcss.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/i686/cmov", {st_mode=S_IFDIR|0755, st_size=1560, ...}) = 0
...
stat64("/lib/i486-linux-gnu", 0xbfab4770) = -1 ENOENT (No such file or directory)
munmap(0xb645e000, 58317)               = 0
open("/usr/lib/xine/plugins/1.1.1/xineplug_inp_mms.so", O_RDONLY) = 26
read(26, "\177ELF\1\1\1\3\3\1\320\27"..., 512) = 512
fstat64(26, {st_mode=S_IFREG|0644, st_size=40412, ...}) = 0
In the above listing which I have truncated for clarity, the line in bold clearly shows that totem is trying to find the library in, among other places, the ‘/lib/tls/i686/cmov/’ directory and the return value of -1 shows that it has failed to find it. So I realized that for totem to correctly play the encrypted DVD, it has to find the libdvdcss.so.2 file in the path it is searching.

Then I used the find command to locate the library and then copy it to the directory /lib/tls/i686/cmov/. Once I accomplished this, I tried playing the DVD again in totem and it started playing without a hitch.

Fig: Totem playing an encrypted DVD Movie
Just to make sure, I took another trace of totem and it showed that the error was rectified as shown by the bold line of output below.
# Output of the second strace on totem
open("/etc/ld.so.cache", O_RDONLY)      = 26
fstat64(26, {st_mode=S_IFREG|0644, st_size=58317, ...}) = 0
old_mmap(NULL, 58317, PROT_READ, MAP_PRIVATE, 26, 0) = 0xb644d000
close(26)                               = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
...
open("/lib/tls/i686/cmov/libdvdcss.so.2", O_RDONLY) = 26
...
stat64("/lib/tls/i686/sse2", 0xbffa4020) = -1 ENOENT (No such file or directory)
munmap(0xb645e000, 58317)               = 0
open("/usr/lib/xine/plugins/1.1.1/xineplug_inp_mms.so", O_RDONLY) = 26
read(26, "\177ELF\1\1\1\3\3\1\360\20"..., 512) = 512
fstat64(26, {st_mode=S_IFREG|0644, st_size=28736, ...}) = 0
Opening the man page of strace, one will find scores of options. For example, if you use the option -t, then strace will prefix each line of the trace with the time of day. One can even specify the system call functions to trace using the -e option. For example, to trace only open() and close() function system calls, one can use the command as follows:
$ strace -o strace.totem -e trace=open,close totem
The ubiquitous strace should not be confused with DTrace that ships with Sun Solaris. strace is just a single tool which takes care of a small part which is tracing a single program. Where as Sun’s DTrace toolkit is much more powerful and consists of a collection of scripts which can track, tune and aid the user in troubleshooting ones system in real time. More over, dtrace is a scripting language with close semblance to C/C++ and awk. Put another way, strace tool in GNU/Linux provides only one of the many functions provided by DTrace in Sun Solaris. That being said, strace plays an important part in aiding the user to troubleshoot ones programs by providing a view of the system calls that the program makes to the Linux kernel.

Installing The Grinder On Ubuntu 10.10

One of my development goals for this year is to learn a lot more about J2EE application performance. Gathering performance statistics for a J2EE application isn’t really difficult, but I soon realized that before I could do that, I needed to find a way to run my applications under load.

At work, we typically do this by using a non-free tool such as LoadRunner. This tool is very popular and it seems to work fairly well, but I can’t afford the license or training costs.

Luckily, I found an open source alternative called The Grinder. This tool’s workflow is similar to the one used by LoadRunner, and fit all of my requirements, including:

  • Free and open source (FOSS)
  • Cross Platform – It is written in Java and runs well for me on Linux and Windows
  • Mature – The software has been around for nearly 10 years and it is currently on version 3
  • Easily Scriptable – You can write load tests using Jython, which is a version of Python that is written in Java.
    • If you haven’t used it before, Python is a great scripting language that does a good job balancing functionality and ease-of-use.
    • Jython is also a very well-established and mature FOSS project. I was using early versions of it as far back as 2001.

The problem is that I had trouble finding many tutorials on using The Grinder. I therefore decided to write a couple of tutorials, covering the following topics:

  1. Installing The Grinder on Ubuntu 10.10
  2. Executing the Hello World test
  3. Recording and executing a test against a local web application

I’ll cover the first bullet point in this article, and I hope to have the other bullet points covered very soon in othe articles.

Installing The Grinder

The Grinder does not include an installation script or startup scripts for some strange reason. You therefore need to do all of this stuff yourself. Here’s how I did it.

Prerequsites

The only prerequisite for The Grinder is Java 1.5 or greater, but some features can only be used with Java 1.6. So let’s install it:

    $ sudo apt-get install sun-java6-jdk

Everything else that you need to run The Grinder is part of the package.

One more thing that you may want to install is the pychecker package. This tool will check your test scripts for any typos or indentation errors. Simply install it like this:

    $ sudo apt-get install pychecker

It’s not required, but it can save you some big headaches later when your script fails to run.

Installing The Package

Since the script doesn’t have a “native” installer and there isn’t an Ubuntu package, we’ll do things the hard way:

  1. Download the latest version of Grinder 3. I’m using version 3.4. This should be a zip file.
  2. Unzip this file in an arbitrary location. For me, this created a folder called grinder-3.4.
    • $ unzip grinder-3.4.zip
  3. Move this Grinder folder under the /opt folder.
    • $ sudo mv grinder-3.4 /opt
  4. To make our lives a little simpler, make yourself the owner of the /opt/grinder. My username is tom, so this is how I would do this:
    • $ sudo chown -R tom:tom /opt/grinder-3.4

Now The Grinder is officially “installed”, but it’s a little clunky to use. Let’s fix that.

Your CLASSPATH

Adding the grinder.jar file to your CLASSPATH variable will make it much easier to use The Grinder:

  1. Open your $HOME/.bash_profile file using a text editor.
  2. Look for a CLASSPATH variable.
  3. If one exists, then add /opt/grinder-3.4/lib/grinder.jar to it.
  4. If the CLASSPATH variable doesn’t exist in this file, then add the following to lines:
    • CLASSPATH=$CLASSPATH:/opt/grinder-3.4/lib/grinder.jar
    • export CLASSPATH

Now either log out and back in or source your .bash_profile file by typing the following command:

    # you should only have to do this the first time
    $ source ~/.bash_profile

Aliases

Once the grinder.jar file is in your classpath, you can start different Grinder components using their full Java path. For example, you should be able to start the Grinder Console using the following command:

    $ java net.grinder.Console

This isn’t terribly difficult, but it’s hard to remember and tedious to type. We’re therefore going to create alias shortcuts for the Console and TCPProxy commands.

Open your $HOME/.bashrc file in a text editor and add the following lines anywhere in the file:

    alias gconsole="java net.grinder.Console"
    alias gproxy="java net.grinder.TCPProxy"

Now either log out and back in or source your .bashrc file by typing the following command:

    # you should only have to do this the first time
    $ source ~/.bashrc

Finally, you can start the Grinder Console and TCPProxy components by simply typing gconsole and gproxy, respectively.

Conclusion

You should now have a working version of The Grinder that is very easy to execute. In my next tutorial, I’ll show you how to execute a hello world test so that you can start to “kick the tires” of The Grinder.

How to reset mysql root password in Ubuntu

I for got my mysql root password last week. , you can reset your mysql root password.
First You have to Stop mysql server:

#service mysqld stop

Now Start mysql server in safe mode with Follwing Options:

#mysqld_safe –user=mysql –skip-grant-tables –skip-networking 

Now you have to Login to mysql server without password:

#mysql -u root mysql

You will get Mysql Prompt.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

Now the Time for Resetting mysql root password:
Run the following commands very carefully ( don’t miss semicolon )

mysql> UPDATE user SET Password=PASSWORD(‘newrootpassword’) WHERE User=’root’;
mysql> flush privileges;
mysql> exit

5) Restart mysql server:

#service mysqld restart

6) Login to MySQL With the New Password:

root@server ]# mysql -u root -p
Enter password:
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> 

Simulation of Arduino programs using virtual breadboard

VirtualBreadboard is a simulation and development environment for embedded applications that use microcontrollers. It is easy to use and can replace a protoboard for experimenting with new designs.It is a freeware. VBB simulates many of the PIC16 and PIC18 microcontroller devices with now Arduino emulation. In addition a wide variety of simulated components such as LCD’s, Servos, logic and other IO devices that can be used to model and simulate high level circuits.

http://www.virtualbreadboard.com/

How to install MySQL on Ubuntu/Debian

It may seem easy for some, but for others, installing MySQL on Ubuntu or Debian Linux is not an easy task. This article explains to you how to install the MySQL Server and Client packages on a Ubuntu/Debian system.

First of all, make sure your package management tools are up-to-date. Also make sure you install all the latest software available.

sudo apt-get update
sudo apt-get dist-upgrade

After a few moments (or minutes, depending on the state of your system), you’re ready to install MySQL. By default, recent Ubuntu/Debian systems install a MySQL Server from the 5-branch. This is a good thing, so don’t worry.

First, install the MySQL server and client packages:

sudo apt-get install mysql-server mysql-client

When done, you have a MySQL database read to rock ‘n roll. However, there’s more to do.

You need to set a root password, for starters. MySQL has it’s own user accounts, which are not related to the user accounts on your Linux machine. By default, the root account of the MySQL Server is empty. You need to set it. Please replace ‘mypassword’ with your actual password and myhostname with your actual hostname.

sudo mysqladmin -u root -h localhost password 'mypassword'
sudo mysqladmin -u root -h myhostname password 'mypassword'

Now, you probably don’t want just the MySQL Server. Most likely you have Apache+PHP already installed, and want MySQL to go with that. Here are some libraries you need to install to make MySQL available to PHP:

sudo apt-get install php5-mysql

Or for Ruby:

sudo apt-get install libmysql-ruby

You can now access your MySQL server like this: mysql -u root -p Have fun using MySQL Server.

Installing Eclipse and the Android SDK on Ubuntu 10.04

I had been playing around with installing the Eclipse IDE (arguably the best Java IDE around) and the Android SDK on my previous Ubuntu installation and basically made a hash of it a few times. Having refined my process I’ve decided to write it down so that I don’t forget ;-) Following my clean installation of Ubuntu 10.04 I needed to get my development environment sorted out, and this meant installing Eclipse and the Android SDK and then wiring them both together.

When downloading the IDE I opted for the ‘Eclipse IDE for Java Developers’ because essentially Android is a set of libraries built on top of Java, so it seemed like a good place to start. Note that I’m using Eclipse 3.5 (Galileo) for my development.

The installation process for Eclipse is a simply case of extracting the downloaded archive into a suitable location, I’ve created a folder called Applications in my /home/Develop directory and extracted the archive into it. Double clicking on the eclipse executable file kicked off the IDE which loaded quite quickly after prompting my for a workspace location – I just kept the default.

So that’s Eclipse sorted, now what about the Android SDK?

After downloading the SDK it too is installed by simply extracting into a suitable location, again I extracted it into my /home/Develop/Applications folder. But we are not quite finished yet – we need to use the SDK Manager to download and install at least one Android development platform first (read the ‘SDK Readme.txt in the folder when you extracted the SDK for more details). This is a simple case on executing the [SDK Folder]/tools/android file either via the command line for by double-clicking it. The SDK and AVD Manager will now load and I simply selected the ‘Available Packages’ option, selected everything in the right-hand pane and clicked on ‘Install Selected’. After a length installation process I was done – this is my SDK/AVD Manager after the installation completed.

SDK and AVD Manager

So that’s it, we’re there yes? Well no, not yet. In the Windows world we are used to installations detecting the presence of IDEs or vice-versa and everything just working once the installer finishes. Well Linux is not like that we need to so some additional configuration before we can get coding; in fact Eclipse/Android installation is pretty much the same on all platforms, so it’s not just an Linux thing.

The first thing to do is to install the Android ADT (Android Developer Tool) plugin into Eclipse – which you’ll be happy to hear is a semi-automatic process.

  • Start Eclipse and select ‘Install New Software’ from the Help menu.
  • Click the ‘Add’ button next to the “Work With” dropdown list
  • Enter a suitable name for this resource, e.g. Android Developer Tools, and the following URL into the location:
    https://dl-ssl.google.com/android/eclipse
  • Click Ok

Eclipse will now search for the ADT plugin and all things being equal will display a screen similar to this:

ADT Install Screen

Select the ‘Developer Tools’ checkbox (which

will select the DDMS and Development Tools beneath it) and click next. After agreeing to the Licence Agreement (which of course you read first) click Finish and the installation will proceed.

You may get a security warning at this point because the packages are apparently unsigned but I just clicked OK to carry on. All things being equal you will be prompted to restart Eclipse and the installation process is then complete.

Selecting File | New you will see ‘Android Project’ displayed and clicking it will display the following window:

New Android Project Dialog

Now I’m still new to Android development so I’ll not inflict my poor knowledge of what you need to enter into this screen – you probably know better than me at the moment anyway ;-)

What I can say is that I managed to complete the obligatory ‘Hello World’ application from my copy of ‘Professional Android 2 Application Development’ book by Reto Meier so I must have it set up somewhere near right.

Android Hello World