Sunday, October 31, 2010

SSH to Virtual machine running as a service

Running virtual box as a service has many advantages however accessibility is limited. Ssh is very famous way to access virtual machines running ssh server.In this blog I will show how to setup ssh on Ubuntu as Guest running over Windows as a host and accessing Ubuntu resources through Windows machine using ssh.

On ubuntu:
$sudo apt-get install ssh

#this will prompt you sshserver. Say yes and install ssh / open-ssh server

$ifconfig

#This command will print your current IP configuration
#As virtual machine in virutal box runs as NAT usually, no static ip is attached to it.
#To ssh we will need a static IP attached to virtualbox. Lets do that.

$sudo vim /etc/network/interfaces

#This will open the file containing network configuration. Comment out existing text and write this:

iface eth0 inet static
address 192.168.10.50
netmask 255.255.255.0
gateway 192.168.1.254


#Now restart your virtual machine
$sudo shutdown -r now

Now on windows machine start putty and ssh to 192.168.10.50.

And this is it if you know your login userid and password for ubuntu.

References:
1) A bog which I dont remember anymore
2) VirtualBox
3) Ubuntu

Running Virtual Machine as Service (virtual box)

Oracle VM Virtual Box is a good utility to try different OSes and keep you host machine clutter free from development installations. Also makes sense to take a regular back up using rsync (file synchronization utility).

This blog post describes shortly how to run virtual box as a service.

To run virtual box as a service we have to start it from command line first and then add the batch / script to scheduled task (on windows) or a cron job ( on unix/linux).

Here are the steps:
1) go to c:\Program Files\Oracle\VirtualBox
2) execute "start /b /wait /low VBoxHeadless -startvm "virtual machine name"
3) press enter

This is it. Now you just need to schedule this execution and now you can run virtual machine in virtual box as a service.

To access virtual machine you can use ssh / remote rdp.

Reference:
http://forums.virtualbox.org/viewtopic.php?f=6&t=1887&start=15

http://www.virtualbox.org

Sunday, October 24, 2010

Optimizing JVM : tips and tricks

Looking at todays fast paced world performance management and optimization is necessary to stay competent. As working on Java currently, JVM optimization is my current research topic.

JVM works certainly good buy by all means can be improved. I read some suggestions here and will summarize them quickly.

Using JAVA_OPTS -Xmx and -Xms
- If JVM is invoking garbage collection too frequently, meaning that your app heap space is not enough. JVM is using garbage collection to free up some space for your app. Result is drastically reduced performance. -Xmx option can be used to increase the heap space.
- Use -Xms switch to enable heap space equal to maximum allocated memory (all your RAM).
- If garbage collection is using too much time of your CPU, use -Xincgc to garbage collect in phases rather than all in one shot.

Benchmarking suite for java

Java Grande, an initiative to promote Java for grande applications. Grande applications are apps which require lots of memory, bandwidth and processing power.

For more information visit JavaG Benchmarking

Saturday, October 23, 2010

Optimize query or filter data on App side

Some days ago I ran into problem where complexity of query became prominent. The query used to return 60000 rows after filters and has to compare them against "IN" block of query which again containing around 60000 keys in them. You can see it is an N^2 complexity.

So the first solution I ran into was to pass 60000 keys to the database. As Java being my (so called sophasticated) language that I am using, I have to use jdbc connectors. As jdbc connectors has limitation of passing only 1000 parameters, it is my problem to tackle with. At this point I was still hoping 60000^2 would be pretty fast on DB side. Coming back to parameters issue, I first used Query.setParameterList(Collection), but failed miserable.

Moving forward and identifying problem decided not to use Query.setParameterList(Collection). However still hoping 60000^2 would work once I can pass the parameters. Now to hack the jdbc a bit, I requested the query string first with a patters in it. The patter would be replaced by 60000 keys which is generated by java program. After replacing the string,query sent to database to do the comparison and I waited ........ Did not come back. ALAS.

An interesting discussion with my colleague suggested that processing data on java would be a better idea. I fastened my seat belts for this experiment. I did the same query but this time just returned all the rows to app side. App was comparing the results, a bit slow but much much faster than SQL query.

Sharing in the benefits of those who believe in getting things done .....

How to use setParameterList

JAVA Link

java.text.SimpleDateFormat

DateFormat dateFormat = new SimpleDateFormat("");

For 20th October, 2010 13:40:19.333, that is 20th October, 1:40 PM and 19 seconds with 333 seconds, the Java mapping would be.

yyyy = 2010
yy = 10 (instead of 2010 only 10 would be printed. Don't forget y2k problem)
MM - 10 (10th month of the georgean calendar)
dd - 20 (20th day of October month)
HH/hh - 01 (should print hour part of date format)
mm - 40 (minute part of the date part)
ss - 10 (seconds of the date part)
SSS - 333 (milliseconds part of the date format)

Usage:

Date d = new Date();
DateFormat datefromat = new SimpleDateFormat("yyyyMMdd HH:mm:ss SSS");
String dateAsString = dateformat.format(d);
System.out.println("The date in text format is:" + dateAsString);

Imports:

java.util.Date
java.text.SimpleDateFormat