install apache benchmarking tool – ‘ab’

On WINDOWS machine :

Download httpd-****-x86 from http://httpd.apache.org/download.cgi

After going through the installation process –> Go to the directory where its installed

similar to C:\httpd-2.4.12-x86\Apache24\bin in my case, add this to system ENV Variable

 

On UNIX machine :

did not work –>> sudo yum install httpd-tools

Below long procedure worked, and it also needed to switch to root user and running it, running command with sudo did not work

You will need to install apr-utils and yum-utils first.

yum -y install apr-util
yum -y install yum-utils

 

extract Apache Benchmark from httpd-tools. And here is how.

mkdir ~/httpd-tools

cd ~/httpd-tools

yumdownloader httpd-tools

 

Now extract ab (Apache Benchmark) and move it to  /usr/bin  folder

rpm2cpio httpd-tools-2.2.24-1.29.amzn1.x86_64.rpm | cpio -idmv

mv usr/bin/ab /usr/bin/ab

cd ~

rm -rf ~/httpd-tools

 

 

sample command to test with –

ab -ki -n 500000 -c 200 http://rusticode.com/2013/04/07/lannn-installing-apache-benchmark-on-centos-ec2-linux-ami-with-nginx/

-n    specifies the number of requests,

-c    number of concurrent connections,

-k    stands for HTTP Keep-Alive,  

-t    maximum time of awaiting for response from connection

Setup up ssh to login without entering password

Considering situation where we need to connect from Server A to Server B

  • On Server A, run the below command to generate the public key

    ssh-keygen -t rsa

    Note: If you don’t have ssh-keygen command recognized in your system, install Git – which will provide required file for running ssh-keygen command.

    After installing Git, add this/similar path to your system environment variable C:\Program Files (x86)\Git\bin\ssh-keygen.exe

    This command should generate id_rsa.pub file in your <homedir>/.ssh/ directory

  • On Server B

    create a folder in the <homedir> with name .ssh

    Copy the id_rsa.pub file from Server A, into this .ssh directory.

    Append the contents of id_rsa.pub file to authorized_keys file inside the .ssh directory on Server B.  If one authorized_keys file does not exist – create it.

That’s it! now we should be able to login without having to enter password every single time.

Loading jndi.properties file from specific path

         Context context = null;
         try {
                File configFile = new File(“<provide absolute path to your my.jndi.properties file>“);
                Properties prop = new Properties();
                FileInputStream istream = new FileInputStream(configFile);
                prop.load(istream);
                context = new InitialContext(prop);
            } catch (NamingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Java Single Jar file with multiple main method classes

/**
* Sample launcher
*/
public class Launcher {

    public static void main(String[] args) throws Exception {
        if (args != null && args.length > 0) {
            String option = args[0];
            String[] args2 = new String[0];

            if (args.length > 1) {
                args2 = new String[args.length – 1];
                System.arraycopy(args, 1, args2, 0, args2.length);
            }

            if (option.equals(“JbossJavaTCPSender”))
                new JbossJavaTCPSender().exec(args2);
            else if (option.equals(“JbossJavaTCPReceiver”))
                new JbossJavaTCPReceiver().exec(args2);
            else
                System.out.println(“Connot find such class to execute having name [“
                        + option+”]”);
        } else
            {
            System.out.println(“Usage : Provide ClassName as an argument to execute.”);
            System.out.println(“\t[java -jar JbossJavaTCPExample.jar JbossJavaTCPSender]”);
            System.out.println(“\t[java -jar JbossJavaTCPExample.jar JbossJavaTCPReceiver]”);
            }
    }
}

java specifying jar file while running program from command line

Solution:

Spent one whole day to figure out semicolon(;) in windows is equivalent to specifying colon(:) on unix platform.

If all of the jars are placed into a folder called ‘jars’ in the current directory.

on Windows –> java -cp .;jars/* AbsoluteClassname arguments

Unix –> java -cp .:jars/* AbsoluteClassname arguments

 

Problem:

Exception in thread “main” java.lang.NoClassDefFoundError:

Java Collections contains Substring

By default list.contains(“String”) check for complete match in each line, so searching for list.contain(“ing”) would return false.

This is what I did for solution:

Convert list collection to String and then search in this complete Collection String contains our substring “ing”

Example: sample code below list elements in list1 that are not present in list2.  Also while comparing it compares only for first 7 characters

String x = list2.toString();
for(String a:list1){
   String b = a.substring(0,7);
   if(!x.contains(b))
       System.out.println(a);
}