Saturday, February 27, 2010

How To Tune Performance of OpenDS

OpenDS logo
Set the following JVM_ARGS in the file $OPENDS_INSTALL_DIR/config/java.properties for the start-ds command.

-Xms1536m -Xmx1536m -XX:NewSize=768m -XX:MaxNewSize=768m -XX:SurvivorRatio=5 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=12 -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:+CMSParallelRemarkEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -XX:+UseTLAB -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+DisableExplicitGC -XX:+HeapDumpOnOutOfMemoryError

Also to prevent the OPENDS HIGH CPU USAGE problem you must enable the beackendDB (berkley JE Database) cache by using the following command.Note that this command can be used while system is running up and have load.Tested enough :)

[root@ochemw bin]# ./dsconfig -h localhost --port 4444 -D "cn=Directory Manager" -w password-X -n set-backend-prop --backend-name userRoot --set db-cache-percent:50
For the details and cache percentage calculations you can refer to the opends perf. tuning page.

Friday, February 26, 2010

A few nice links

http://www.tutorialspoint.com/java/
http://www.exampledepot.com/

Dating with Date and Flirting with Calendar

import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Set;
import java.util.*;
import java.util.Collections;
import java.text.SimpleDateFormat;
import java.text.ParseException;

public class DatingWithDate {

private static final SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
protected final static long MILLSECS_PER_DAY = 24L * 60L * 60L * 1000L;

public static void main (String[] args) throws IOException, ParseException {
Calendar now = Calendar.getInstance();
printCalendar (now);
now.add(Calendar.DAY_OF_YEAR,1);
printCalendar (now);
System.exit(0);

}
private static void printCalendar(Calendar calendar)
{
String date = df.format(calendar.getTime());
System.out.println(date);
}

}

Tuesday, February 23, 2010

Command line Reader Sample

import java.io.*;
import java.lang.*;

public class DecimalToOctal {
public static void main(String[] args) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the decimal number:");
String deci = buff.readLine();
int value = Integer.parseInt(deci);
String str = Integer.toString(value,8);
System.out.println("octal:=" + str);
}
}

Monday, February 22, 2010

Blocking Queue Sample

import java.util.*;
import java.util.concurrent.*;
import java.io.*;


public class BlockingQueue {
    private static List waitingCustomerList = null;
    private static final String filePath = "/home/serkans/phoneNumbersOnly.txt";
    private static ArrayBlockingQueue waitingCustomersQueue = null;


    public static void main (String[] args)  {


        loadNumbers();


        initializeBlockingQueue();


        Runnable callcenterGirl = new Runnable (){
            public void run () {
                while (true) {


                 String phoneNumber = null;
                 try {
                     phoneNumber = waitingCustomersQueue.poll (10000L, TimeUnit.MILLISECONDS);
                     if (null != phoneNumber){
                         System.out.println (" -- Callcenter girl is helping to : " + phoneNumber);
                     }else{
                         System.out.println ( " -- Callcenter girl is waiting  : " + phoneNumber);
                     }
                 } catch (InterruptedException ex) {
                     System.out.println ("  -- Callcenter girl is interrupted ex:");
                     ex.printStackTrace();
                 }
             }


         }
        };


        Thread t = new Thread (callcenterGirl);
        t.start();




    }


    private static ArrayBlockingQueue initializeBlockingQueue () {
        try {
            waitingCustomersQueue = new ArrayBlockingQueue(waitingCustomerList.size (), true, waitingCustomerList);
        } catch (Exception ex) {
            ex.printStackTrace();
            System.exit(1);
        }
        return waitingCustomersQueue;
    }


    private static void loadNumbers () {
        Properties props = new Properties();
        try {
            props.load (new FileInputStream (new File (filePath)));
            System.out.println (" -- item count in file is :" + props.size());
            waitingCustomerList = new ArrayList (props.keySet());
        } catch (IOException ex) {
            System.out.println (" -- Unable to find file : "+filePath);
        }
    }
}