Sunday, April 29, 2012

JVM heap size [ missed concepts ]

This is regarding the  concept of JVM heap size when running on  machines having larger  RAM .The primary advantage of running Java in a 64-bit environment is the larger address space. This allows for a larger Java heap size and an increased maximum number of Java Threads. It's important to note that 64-bit implementation doesn't mean that that built-in Java types (such as integers) are doubled in size from 32 to 64.

However, addressing larger amounts of memory come with a small performance loss in 64-bit VMs (compared to a 32-bit VM) because every reference takes 8 bytes instead of 4.
Loading these extra 4 bytes per reference impacts the memory usage, which causes slightly slower execution (depending on how many pointers get loaded during the Java program's execution).

64-bit Java implementation enables to create and use more Java objects, thus breaking the 1.5-1.6 GB heap limit we have in 32 bit.

below is the command that will set minimum and maximum  heap size for application

java -d64 -Xms2g -Xmx80g MyApp

The above JVM args does not create a process with 80g heap. It only creates a process with 2g of Heap and will only grow till 80g if required and if RAM is available.
by specifying Xmx80g, one is only restricting the maximum heap size that the Java process can use.
When the heap size exceeds the limit specified memory , the behavior of  allocating memory to java process depends on OS.OS can allocate more memory from with in the RAM ( if there is any free space not being used by other user processes or it can allocate memory from disk ) . If heap size size exceeds physical memory then the heap begins swapping to disk which causes Java performance to drastically decrease. It has been observed that after a threshold  memory reaches the performance of application wont  increase considerably by increasing heap size.
For more details on this study click at below link
http://docs.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/5/html/Performance_Tuning_Guide/chap-Performance_Tuning_Guide-Java_Virtual_Machine_Tuning.html

The bigger the heap size slower (after a threshold value ) will be performance because it will make GC to be a hazardous task to run.Because the more of time spent on GC. The performance of the application highly depends on how one size the heap generations and GC parameters.

Sun recommends to enable either the Parallel or Concurrent garbage collectors when running with heaps larger than 2 GB.These collectors attempt to minimize the overhead of collection time by either of the following:
-       collecting garbage concurrent with the execution of your Java application
-       utilizing multiple CPUs during collections

Here is good link  providing some info about how to improve performance in multi processor environment.
http://www.jroller.com/imeshev/entry/effect_of_jvm_heap_size

If a web server like jboss is running .it will have its separate heap space than any web application deployed on it .
any webservice deployed and running in it will use its own address space by explicitly giving jvm args to it .

Friday, April 20, 2012

synchronization Do and Do Nots

Its very likely who don't program often multithreading in their code to synchronize on objects that can later  create big trouble. Recently i did some mistakes and so i am writing here lesson learned from  it.
  • Never synchronize such object that can have NULL value ( at some instance of  program ).
  • Never synchronize on string literals . like ( String str="hello" ) here str is string literal not an object.
  • Better to call synchronization over object that never changes its state.
  • Avoid making synchronized methods unless its not required , since that can hold lock form  whole time during its execution.
still learning ....

Thursday, April 12, 2012

MySQL titbits .....................2

Are you annoyed by loud echo sound whenever you type a wrong sql command on cursor?
Just give -b while logging into command prompt .

mysql -b -u root

you will get rid of error prompts.

Tuesday, April 10, 2012

MySQL titbits .....................1


Today my friend asked how to create procedures in MySQL ... i just created this small example to get her a clue.

___________________________

procedure definition.
___________________________


DELIMITER $$
DROP PROCEDURE IF EXISTS myProc$$
CREATE PROCEDURE myProc()
BEGIN
DECLARE myvar char(10);
DECLARE len, ctr int DEFAULT 1;
SELECT count(*) INTO len FROM ss_temp ;

WHILE ctr<=len DO
select ctr;
SELECT name INTO myvar FROM ss_temp WHERE sub_id= ctr;

IF myvar ='songs' THEN
update ss_temp set name='Jokes' where sub_id=ctr;
ELSE
update ss_temp set name='songs' where sub_id=ctr;
END IF;
SET ctr = ctr + 1;
END WHILE;

END$$
DELIMITER ;

__________________________

check if procedure exists

SHOW PROCEDURE STATUS;
________________________

call procedure

call myProc();

_______________________

Tuesday, April 3, 2012

Networking Protocols Categorization

Networking layer divisions

Layer 1 Based on symbols . Physical layer
Layer 2 Based on Frames . Link Layer ARP/OSPF /PPP/ MAC /
Layer 3 Based on Packets . Natework Layer ICMP/IPV6/IGMP/IPSec
Layer 4 Based on Segmanets . Transport Layer TCP/UDP/RSVP/SCTP
Layer 5 Based on Messgaes . Application Layer Protocols SMPP/SMTP/SIP/SNMP/HTTP/FTP/SSH/DHCP/DNS/TELNET
.

All those protocols that send messages are application layer protocols . Like SMPP /SIP that are text based protocols . However the messages are being sent over TCP Layer 4 .

Monday, April 2, 2012

Must known basics in Java

How to print integer value of a char in java?.......................by typecasting data type (int)'a'
what will be output of char ch=296; sysout(ch).......................?
is it valid declaration ? float a=0.7; .........................................No
what will it print ? int i=+-30; or int i=-+30 ............................-30
what will it print int i=10/0; sysout (i); ...................................Airthmatic Exception
what will it print double d=10/0.0; sysout (d); .......................-Infintiy (Double.NEGATIVE_INFINITY)