Wednesday, March 18, 2009

Sync Linux server Time w. NTP server

Synchronize
ntpdate -b pool.ntp.org

configuration
vi /etc/ntp.conf


References: http://www.brennan.id.au/09-Network_Time_Protocol.html

  1. Logged in as root, check which timezone your machine is currently using by executing `date`. You'll see something like Mon 17 Jan 2005 12:15:08 PM PST, PST in this case is the current timezone.
  2. Change to the directory /usr/share/zoneinfo here you will find a list of time zone regions. Choose the most appropriate region, if you live in Canada or the US this directory is the "America" directory.
  3. If you wish, backup the previous timezone configuration by copying it to a different location. Such as
    mv /etc/localtime  /etc/localtime-old
  4. Create a symbolic link from the appropiate timezone to /etc/localtime. Example:
    ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
  5. If you have the utility rdate, update the current system time by executing
    /usr/bin/rdate -s time.nist.gov
  6. Set the ZONE entry in the file /etc/sysconfig/clock file (e.g. "America/Los_Angeles")
  7. Set the hardware clock by executing:
    /sbin/hwclock --systohc

Glassfish web container tuning settings

Reference: http://docs.sun.com/app/docs/doc/820-4343/abedw?a=view

Web Container Settings

Set Web container properties with the Admin Console at Configurations > config-name > Web Container.

Session Properties: Session Timeout

Session timeout determines how long the server maintains a session if a user does not explicitly invalidate the session. The default value is 30 minutes. Tune this value according to your application requirements. Setting a very large value for session timeout can degrade performance by causing the server to maintain too many sessions in the session store. However, setting a very small value can cause the server to reclaim sessions too soon.

Manager Properties: Reap Interval

Modifying the reap interval can improve performance, but setting it without considering the nature of your sessions and business logic can cause data inconsistency, especially for time-based persistence-frequency.

For example, if you set the reap interval to 60 seconds, the value of session data will be recorded every 60 seconds. But if a client accesses a servlet to update a value at 20 second increments, then inconsistencies will result.

For example, consider an online auction scenario as follows:

  • Bidding starts at $5, in 60 seconds the value recorded will be $8 (three 20 second intervals).

  • During the next 40 seconds, the client starts incrementing the price. The value the client sees is $10.

  • During the client’s 20 second rest, the Application Server stops and starts in 10 seconds. As a result, the latest value recorded at the 60 second interval ($8) is be loaded into the session.

  • The client clicks again expecting to see $11; but instead sees is $9, which is incorrect.

  • So, to avoid data inconsistencies, take into the account the expected behavior of the application when adjusting the reap interval.

Disable Dynamic JSP Reloading

On a production system, improve web container performance by disabling dynamic JSP reloading. To do so, edit the default-web.xml file in the config directory for each instance. Change the servlet definition for a JSP file to look like this:


jsp
org.apache.jasper.servlet.JspServlet

development
false


xpoweredBy
true


genStrAsCharArray
true
3

Tuesday, March 17, 2009

MySQL Database Replication

http://aciddrop.com/2008/01/10/step-by-step-how-to-setup-mysql-database-replication/

http://www.howtoforge.com/mysql_database_replication

http://www.onlamp.com/pub/a/onlamp/2005/06/16/MySQLian.html

http://osdir.com/ml/db.mysql.java/2004-10/msg00011.html

Putty show server ipaddress

Add the below to vi ~/.bashrc

add IP=`ifconfig eth0|grep inet\ addr|cut -d " " -s -f 12|cut -d : -s -f 2`
export PS1='${debian_chroot:+($debian_chroot)}\u@$IP:\w\$ '

Monday, March 16, 2009

How to Get the Best Performance Out of a Java Persistence Implementation

Ref: http://blogs.sun.com/enterprisetechtips/entry/how_to_get_the_best

http://dev.mysql.com/tech-resources/articles/connection_pooling_with_connectorj.html

Multiple MYSQL Instance reference

http://code.openark.org/blog/mysql/manually-installing-multiple-mysql-instances-on-linux-howto
http://www.ducea.com/2009/01/19/running-multiple-instances-of-mysql-on-the-same-machine/
http://dev.mysql.com/doc/refman/5.1/en/multiple-unix-servers.html
http://blog.dbadojo.com/2008/01/multiple-mysql-instances-on-ec2.html
http://forums.mysql.com/read.php?79,27,85#msg-85

Tuesday, March 10, 2009

Java Access Control

Access Levels
Modifier Class Package Subclass World
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N

Public – access allowed to public. E.g., constants
Protected – allow child to access parent.
No modifier – allow package member to access only.
Private – non-accessible.


Static Initialize
- init static constant variables or object
- loaded before class is loaded
- prevents lock scenario

static
{
*action
}