Wednesday, April 28, 2010

AJAX LOAD TEST USING JMETER

Here are some steps:
1. Create new test plan
2. Under the Test Plan, add Config Element > Http Request Defaults
- Enter server name and port number
3. Under Test Plan, add Config Element > HTTP Cookie Manager
4. Add Thread Group under Test Plan
5. Under the Thread Group, Add > Logic Controller > Recording Controller
6. Test Plan > Add > Listener > Aggregate Report
7. Under Workbench, Add > Non-Test Element > HTTP Proxy Server
- Port 9090
- Target Controller: Thread Group > Recording Controller
- Patterns to include: Click Add then enter “.*”
8. Under HTTP Proxy Server, Add > Timer > Gaussian Random Timer
- Set Constant Delay Offset (in milliseconds): ${T}
9. Bring up the FireFox browser and under Tools/options/advanced tab/network tab/settings button/”Manual proxy configuration”
- Set 127.0.0.1 port 9090
- Enable checkbox: “Use this proxy for all protocols”
10. Bring up HTTP Proxy Server, then click Start.
11. Now simply bring up FF and perform operations you wish to be recorded into the recording controller.
12. When complete, click the “Stop” button on the HTTP Proxy Server.
13. Verify that operations were recorded on the “Recording Controller”.

=================

1. set

CookieManager.save.cookies=true

in jmeter.properties file.

2. get the session ID as COOKIE_JSESSIONID

3. define variable for script session id as ${__javaScript('B4B26203309DA29AEB9542780F307009'+Math.floor(Math.random() * 1000))}

4. use these session id and script session id in the dwr request.

Tuesday, April 27, 2010

JMETER BASIC TEST STEPS

Here are some steps:
1. Create new test plan
2. Under the Test Plan, add Config Element > Http Request Defaults
- Enter server name and port number
3. Under Test Plan, add Config Element > HTTP Cookie Manager
4. Add Thread Group under Test Plan
5. Under the Thread Group, Add > Logic Controller > Recording Controller
6. Test Plan > Add > Listener > Aggregate Report
7. Under Workbench, Add > Non-Test Element > HTTP Proxy Server
- Port 9090
- Target Controller: Thread Group > Recording Controller
- Patterns to include: Click Add then enter “.*”
8. Under HTTP Proxy Server, Add > Timer > Gaussian Random Timer
- Set Constant Delay Offset (in milliseconds): ${T}
9. Bring up the FireFox browser and under Tools/options/advanced tab/network tab/settings button/”Manual proxy configuration”
- Set 127.0.0.1 port 9090
- Enable checkbox: “Use this proxy for all protocols”
10. Bring up HTTP Proxy Server, then click Start.
11. Now simply bring up FF and perform operations you wish to be recorded into the recording controller.
12. When complete, click the “Stop” button on the HTTP Proxy Server.
13. Verify that operations were recorded on the “Recording Controller”.

Friday, April 02, 2010

AWSTATS on ubuntu

Install Awstats on Ubuntu

This has been tested with Ubuntu server 8.04 (Hardy Heron).

Installation

sudo aptitude install awstats
To see the country of your visitors (not required)

sudo aptitude install libnet-ip-perl
sudo aptitude install libgeo-ipfree-perl
Configuration

Let's assume you want to analyze the Apache 2 log file of your website “toto.com” (It can be just an IP address).

Create configuration file

sudo cp /etc/awstats/awstats.conf /etc/awstats/awstats.toto.com.conf
Update these parameters

# apache2
LogFile="/var/log/apache2/access.log"

# domain name
SiteDomain="toto.com"
HostAliases="localhost 127.0.0.1 toto.com"

LogFormat=1
You can also activate these plugins

LoadPlugin="tooltips
LoadPlugin="geoipfree"
Run

sudo /usr/lib/cgi-bin/awstats.pl -config=toto.com -update
You should get something like this

Create/Update database for config "/etc/awstats/awstats.toto.com.conf" by AWStats version 6.7 (build 1.892)
From data in log file "/var/log/apache2/access.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 191338
Found 0 dropped records,
Found 24 corrupted records,
Found 0 old records,
Found 191314 new qualified records.
Configure Apache to view the statistics

Create /etc/apache2/conf.d/statistics

Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /statistics/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Restart Apache

sudo /etc/init.d/apache2 restart
View your statistics

http://toto.com/statistics/awstats.pl
or (in case you have more than one config file)

http://toto.com/statistics/awstats.pl?config=toto.com
Update your statistics with cron

In /etc/crontab add

# update every 10 min
*/10 * * * * root /usr/lib/cgi-bin/awstats.pl -config=toto.com -update > /dev/null
How to reset awstats

Just delete the files in /var/lib/awtstats (directory defined by DirData parameter)

sudo su - root
cd /var/lib/awstats
rm *
logout
Notes

you have to be root because for some reason, sudo rm -R awstats/* wouldn't work.
if you get the message Never updated (See 'Build/Update' on awstats_setup.html page) whereas the awstats files are there in /var/lib/awtstats, it's probably a permission problem on this folder.
Source: http://awstats.sourceforge.net/docs/awstats_faq.html#RESET

Troubleshooting

awstats "Error: SiteDomain parameter not defined in your config/domain file. You must edit it for using this version of AWStats. "
Try to this URL (with your values): http://toto.com/statistics/awstats.pl?config=toto.com

Reference

http://ubuntu-tutorials.com/2008/01/16/configuring-awstats-on-ubuntu-server/
http://www.mneylon.com/blog/archives/2005/08/03/configuring-awstats-with-apache-2-on-ubuntu/
http://awstats.sourceforge.net/
http://awstats.sourceforge.net/docs/awstats_faq.html

Tomcat on ubuntu amazon ec2

There’s a better workaround so you can keep Ubuntu’s Tomcat6 (taken from http://ubuntuforums.org/showthread.php?p=8541057, by DisDis)

In a terminal:

1. sudo apt-get install tomcat6
2. cd /usr/share/tomcat6
3. sudo ln -s /var/lib/tomcat6/conf conf
4. sudo ln -s /etc/tomcat6/policy.d/03catalina.policy conf/catalina.policy
5. sudo ln -s /var/log/tomcat6 log
6. sudo chmod -R 777 /usr/share/tomcat6/conf

sudo apt-get install tomcat6 cd /usr/share/tomcat6 sudo ln -s /var/lib/tomcat6/conf conf sudo ln -s /etc/tomcat6/policy.d/03catalina.policy conf/catalina.policy sudo ln -s /var/log/tomcat6 log sudo chmod -R 777 /usr/share/tomcat6/conf

There. Now just go to Window/Preferences/Sever/Runtime Environments, add the Apache Tomcat6 Server and use /usr/share/tomcat6 as the installation directory!

Tuesday, March 30, 2010

Ubuntu VNC keyboard Sync Issue AMAZON EC2

Applications -> System Tools -> Configuration Editor
Desktop -> Gnome -> Peripherals -> Keyboard -> KBD

Edit the layout key to delete what is there and add your "abfh" by typing asdf.

Then go to the Keyboard preferences and put back in US-105 if that's what you like.
System -> Preferences -> Keyboard
Layouts
Add
Choose your favorite. Hit OK, mark as default.

Restart VNC/EC2 Instance, and hope it works.

VNC ON UBUNTU AMAZON EC2

VNC on Ubuntu Feisty
I recently had the exciting opportunity to give Amazon EC2 a spin and as a first-time Linux-experiment, I opted to use Clint Pells' Ubuntu Feisty image with an aim to set up Ruby on Rails and some other goodies.

The goal

Coming from a Windows background, and having been spoiled with fancy GUI tools, the SSH terminal access felt somewhat intimidating, so I wanted remote-desktop-like connectivity to my EC2 instance. The following instructions outline the exact steps to connect to your EC2 Ubuntu image via VNC from your Windows Machine. At the time of writing, my knowledge of Linux systems is limited to the 5 hours I spent mucking around with my installation, so I am writing this tutorial for fellow developers that need a no-nonsense step-by-step guide.

Requirements

First, this is what you will need:
A running instance of the Ubuntu Feisty AMI (ami-898560e0)
Putty SSH client on your Windows machine that is connected to your instance
TightVNC Viewer on your Windows machine
Getting Your Hands Dirty

1. Make sure Ubuntu is updated

This is simple; type this in from your terminal:

sudo apt-get update

2. Install the Desktop Environment

The Ubuntu image that we are using does not have a Window manager, so we need to install this first on the server. This may take a while since it needs to be downloaded. In your terminal, type in:

sudo apt-get install x-window-system-core xserver-xorg gnome-desktop-environment

3. Install TightVNC Server

Next, we install the VNC server that we will be using.

sudo apt-get install tightvncserver

At one point, this will show a screen asking you to select screen dimensions, but I was content with the default options and just hit continue.

4. Launch the server

First we run VNCServer to set the password (I know you are probably lazy, but make it a $tR0nG password). In your terminal, type in:

vncserver

Next, set up a session ... By default, port :0 corresponds to port 5900, :1 to 5901 etc. Remember that no 'firewall configuration' is necessary since we will be using a SSH tunnel for security.

vncserver :1

This returns a message similar to New 'X' desktop is domU-XX-XX-XX-XX-XX-XX:1

5. Configure SSH Tunnel in Putty

Close down your SSH session and open Putty again. Under Category, go to Connection>SSH>Tunnels. In Source port, put 5901; in Destination, put your instance DNS name followed by :5901 i.e. ec2-XXX-XXX-XXX-XXX.z-2.compute-1.amazonaws.com:5901

6. Connect with VNCViewer

Open TightVNCViewer, and type in localhost:1, then hit OK. Then type in the VNC server password that you created in step 4. Once it launches, it may look crummy and ugly. If this is the case, it is because you didn't use the VNCViewer for fast compression. Next, you will notice a command screen but nothing else. DON'T PANIC! - I didn't set you up. Just type:

gnome-session

This will bring up the desktop environment and display a list of errors that you can ignore.

7. IMPORTANT: Shutting down your session

Lastly, you will need to know how to shutdown the VNCServer Session that you created. Simply type in the following from your SSH command prompt:

vncserver -kill :1

You are now Golden

You are now ready to access your EC2 instance securely and easily. Until next time ...

AMAZON EC2 LINUX STUFF

vnc on ubuntu ec2

http://dotnetrehab.blogspot.com/2007/04/vnc-on-ubuntu-feisty.html

java on ubuntu ec2:

http://www.ubuntugeek.com/how-to-install-java-runtime-environment-jre-in-ubuntu.html


keyboard issue on ubuntu

https://bugs.launchpad.net/ubuntu/+source/vino/+bug/112955/comments/31


java on ubuntu
http://www.java.com/en/download/manual.jsp
http://www.java.com/en/download/help/5000011400.xml

tomcat on ubuntu
http://ubuntuforums.org/showthread.php?p=226828

postgresql on ubuntu ec2

http://deadprogrammersociety.blogspot.com/2009/08/postgresql-on-ubuntu-on-ec2.html


Build AMI and upload to S3

http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/index.html?creating-an-image.html


mounting ebs to ec2 linux

http://clouddevelopertips.blogspot.com/2009/08/mount-ebs-volume-created-from-snapshot.html
http://www.randomtools.net/how-to-mount-amazon-ec2-ebs-volume-on-an-instances-file-system-76.html

Thursday, January 21, 2010

PDFTOHTML ON UBUNTU

PDFTOHTML : is a tool which would help to convert pdf files into html,xml files

http://pdftohtml.sourceforge.net/

the library could be installed on Ubuntu using the following commands

apt-get install poppler-utils

apt-get install pdftohtml

once done, you could just type pdftohtml to see whether it's installed properly or not. If its installed, you could see the help information displayed.

Cheers!

Wednesday, January 13, 2010

Use of BigDecimal

Working with floating point numbers can be fun. Typically, when working with amounts, you automatically think of using a double type, unless the value is a whole number, then an int type is typically sufficient. A float or long can also work out, depending upon the size of a value. When dealing with money, though, these types are absolutely the worst thing you can use as they don't necessarily give you the right value, only the value that can be stored in a binary number format. Here is a short example that shows the perils of using a double for calculating a total, taking into account a discount, and adding in sales tax.

The Calc program starts with an amount of $100.05, then gives the user a 10% discount before adding back 5% sale tax. Your sales tax percentage may vary, but this example will use 5%. To see the results, the class uses the NumberFormat class to format the results for what should be displayed as currency.

import java.text.NumberFormat;

public class Calc {
public static void main(String args[]) {
double amount = 100.05;
double discount = amount * 0.10;
double total = amount - discount;
double tax = total * 0.05;
double taxedTotal = tax + total;
NumberFormat money = NumberFormat.getCurrencyInstance();
System.out.println("Subtotal : "+ money.format(amount));
System.out.println("Discount : " + money.format(discount));
System.out.println("Total : " + money.format(total));
System.out.println("Tax : " + money.format(tax));
System.out.println("Tax+Total: " + money.format(taxedTotal));
}
}
Using a double type for all the internal calculations produces the following results:

Subtotal : $100.05
Discount : $10.00
Total : $90.04
Tax : $4.50
Tax+Total: $94.55
The Total value in the middle is what you might expect, but that Tax+Total value at the end is off. That discount should be $10.01 to give you that $90.04 amount. Add in the proper sales tax and the final total goes up a penny. The tax office won't appreciate that. The problem is rounding error. Calculations build on those rounding errors. Here are the unformatted values:

Subtotal : 100.05
Discount : 10.005
Total : 90.045
Tax : 4.50225
Tax+Total: 94.54725
Looking at the unformatted values, the first question you might ask is why does 90.045 round down to 90.04 and not up to 90.05 as you might expect? (or why does 10.005 round to 10.00?) This is controlled by what is called the RoundingMode, an enumeration introduced in Java SE 6 that you had no control over in prior releases. The acquired NumberFormat for currencies has a default rounding mode of HALF_EVEN. This means that when the remaining value is equidistant to the edges, to round towards the even side. According to the Java platform documentation for the enumeration, this will statistically minimize cumulative errors after multiple calculations.

The other available modes in the RoundingMode enumeration are:

CEILING which always rounds towards positive infinity
DOWN which always rounds towards zero
FLOOR which always rounds towards negative infinity
UP which always rounds away from zero
HALF_DOWN which always rounds towards nearest neighbor, unless both neighbors are equidistant, in which case it rounds down
HALF_UP which always rounds towards nearest neighbor, unless both neighbors are equidistant, in which case it rounds up
UNNECESSARY which asserts exact result, with no rounding necessary
Before looking into how to correct the problem, let us look at a slightly modified result, starting with a value of 70 cents, and offering no discount.

Total : $0.70
Tax : $0.03
Tax+Total: $0.74
In the case of the 70 cent transaction, it isn't just a rounding problem. Looking at the values without formatting, here's the output:

Total : 0.7
Tax : 0.034999999999999996
Tax+Total: 0.735
For the sales tax the value 0.035 just can't be stored as a double. It just isn't representable in binary form as a double.

The BigDecimal class helps solve some problems with doing floating-point operations with float and double. The BigDecimal class stores floating-point numbers with practically unlimited precision. To manipulate the data, you call the add(value), subtract(value), multiply(value), or divide(value, scale, roundingMode) methods.

To output BigDecimal values, set the scale and rounding mode with setScale(scale, roundingMode), or use either the toString() or toPlainString() methods. The toString() method may use scientific notation while toPlainString() never will.

Before converting the program to use BigDecimal, it is important to point out how to create one. There are 16 constructors for the class. Since you can't necessarily store the value of a BigDecimal in a primitive object like a double, it is best to create your BigDecimal objects from a String. To demonstrate this error, here's a simple example:

double dd = .35;
BigDecimal d = new BigDecimal(dd);
System.out.println(".35 = " + d);
The output is not what you might have expected:

.35 = 0.34999999999999997779553950749686919152736663818359375
Instead, what you should do is create the BigDecimal directly with the string ".35" as shown here:

BigDecimal d = new BigDecimal(".35");
resulting in the following output:

.35 = 0.35
After creating the value, you can explicitly set the scale of the number and its rounding mode with setScale(). Like other Number subclasses in the Java platform, BigDecimal is immutable, so if you call setScale(), you must "save" the return value:

d = d.setScale(2, RoundingMode.HALF_UP);
The modified program using BigDecimal is shown here. Each calculation requires working with another BigDecimal and setting its scale to ensure the math operations work for dollars and cents. If you want to deal with partial pennies, you can certainly go to three decimal places in the scale but it isn't necessarily.

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Calc2 {

public static void main(String args[]) {
BigDecimal amount = new BigDecimal("100.05");
BigDecimal discountPercent = new BigDecimal("0.10");
BigDecimal discount = amount.multiply(discountPercent);
discount = discount.setScale(2, RoundingMode.HALF_UP);
BigDecimal total = amount.subtract(discount);
total = total.setScale(2, RoundingMode.HALF_UP);
BigDecimal taxPercent = new BigDecimal("0.05");
BigDecimal tax = total.multiply(taxPercent);
tax = tax.setScale(2, RoundingMode.HALF_UP);
BigDecimal taxedTotal = total.add(tax);
taxedTotal = taxedTotal.setScale(2, RoundingMode.HALF_UP);
System.out.println("Subtotal : " + amount);
System.out.println("Discount : " + discount);
System.out.println("Total : " + total);
System.out.println("Tax : " + tax);
System.out.println("Tax+Total: " + taxedTotal);
}
}
Notice that NumberFormat isn't used here, though you can add it back if you'd like to show the currency symbol.

Now, when you run the program, the calculations look a whole lot better:

Subtotal : 100.05
Discount : 10.01
Total : 90.04
Tax : 4.50
Tax+Total: 94.54
BigDecimal offers more functionality than what these examples show. There is also a BigInteger class for when you need unlimited precision using whole numbers. The Java platform documentation for the two classes offers more details for the two classes, including more details on scales, the MathContext class, sorting, and equality.