Useful tools for techies especially for developers and sys admin

There are many situation in programming and testing where we can use these tools to get our work done faster and effectively.

1) Firebug Download
Very interesting tool. Can not live without it if you really have to do Javascript and CSS testing. Not only that it also helps in request tracking and cookie management.

2) FireCookie download
Another interesting FireFox add on for cookie management. You can change the cookie on the fly and add new cookie whenever required. Very use full if your site is using cookie intensively.

3) YSlow Download
Add on to firefox, very use full if you have to asses performance of your site. specially recommendation and site score by Yslow is use full to improve overall performance of site.

4) Web Developer Download
Add on to firefox. You can do ton of things from debugging java script to changing and testing css, HTML on the fly with web developer tool. Have to have tool for HTML developer.

5) HTTP Watch Download
Very use full tool for both IE and firefox for inspecting http traffic on site. Very use full to debug some performance issue. Can watch AJAX request and response and debug it. You cn also use Net tab in firebug for same perpose though. But some time I feel Net tab doesn’t work, HTTP Watch is more relaiable.

6) Fiddler Download
ooooo … debugging traffic and web issue in IE is really difficult. Fiddler is one of those tool that can help to watch traffic on site easily.

7) Samurai Thread dump analyzer Download
Very use full tool to analyze thread dump. If your site is having performance issues (100% CPU usage). You can use this tool to analyze all the waiting threads. You can take thread dump using command kill -3

8) JadEclipse Download JAD Executable Download
Use full tool to decompile class file in eclipse. After installing JAD eclipse, go to windows -> preferences -> Jad Eclipse -> and set Path to decompiler as C:JADjad.exe and Directory as temp file as D:TEMP. for jad eclipse to work.

9) Jmeter Download
Very use full tool to do load testing. Since this tool is free you can easily do load testing on your site whenever you want. Also this tool is very easy to set up and configure.

10) HTML Parser Download
Another Use full free java API to parse HTML. Documentation of this API is not good though with some inspection you will find this API very interesting and easy to use.

11) Regular Expression check Link
If you are using regular expression a lot, this web site will help you to create and test your regular expression. I use this link quite often to test my regex expressions.

12) Key Notes Download
Well, This is not any tool as such but very use full to keep your notes.

13) Java Code analyzer tool Download Download for eclipse
It is a very use full tool to analyze Java code performance. There are plug ins available for many IDE. Tool also tells you if you have any code issue in your code (Null pointer exception and all). Very use full to develop a quality code.

14) Message Post tool (Wget) Download
Wget is very handy massage POST tool and can be used to POST XML across applications.

15) Visual VM (Java Profiling tool) Download
Very nice and neat free Java profiling tool. For enterprise application I will even recommend YourKit Download. But for quick and free memory issue problems you can can use this tool effectively. You should have Java 6.0 for this to run.

16) Any Edit plugin for eclipse Download
If the JSP pages contains a lot of white spaces or tabs, it may take more time to load the page and requires more network band width. Any Edit is a nice tool to remove unnecessary spaces from the page.

17) Heap Dump Analyzer (MAT) Download
Some time your application suffer with memory issues, for example out of memory error. And you don’t have any idea what is going on. There are many different reasons for out of memory error but most common is memory leak. Eclipse Memory Analyzer (MAT) is a power full to tool to analyze heap dump and narrow down the problem. Please note that you should have -XX:+HeapDumpOnOutOfMemoryError parameter set to collect heap dump. Java 1.6 also comes with a tool called jmap (memory map) to force heap dump. More information can be found here.

Setup Global load balancing for your site using Open source nginx

 

 

Nginx, called engine-x is a high performance HTTP server and reverse proxy, with proxy capabilities for IMAP/POP3/SMTP. Nginx is the creation of Russian developer, Igor Sysoev, and has been running in production for over two years. The latest stable release at the time of writing is Nginx 0.5.30, and is the focus of this article. While Nginx is capable of proxying non-HTTP protocols, we’re going to focus on HTTP and HTTPS.

 

High Performance, Yet Lightweight

Nginx uses a master process and N+1 worker process model. The number of workers is controlled by the configuration, yet the memory footprint and resources used by Nginx are several orders of magnitude less than Apache. Nginx uses epoll() in Linux. In our lab, Nginx was handling hundreds of requests per second, while using about 16MB of ram and a consistent load average of about 1.00. This is considerably better than Apache 2.2, and Pound doesn’t scale well with this type of usage (high memory usage, lots of threads). In general, Nginx offers a very cost effective solution.

 

Lighttpd

Lighttpd is a great lightweight option, but it has a couple of drawbacks. Nginx has very good reverse proxy capabilities with integrated basic load balancing. This makes it a very good option as a front end to dynamic web applications, such as those running under Rails and using Mongrel. Lighttpd on the other hand, has an old and unmaintained proxy module. Now it does have a new proxy module with Lighttpd 1.5.x, but that is the other problem with Lighttpd, where its going. Lighttpd 1.4 is lightweight, relies on very few external libraries and is fast. Lighttpd 1.5.x on
the other hand requires many more external libraries, including glib, now I don’t know about you but anything using glibc is far from “lightweight”.

 

Basic Configuration

The basic configuration of Nginx specifies the unprivileged user to run as, the number of worker processes, error log, pid and events block. After this basic configuration block, you have per protocol blocks (http for example).

 

 

  • user nobody;
  • worker_processes 4;
  • error_log logs/error.log;
  • pid logs/nginx.pid;
  • events {
  • worker_connections 1024;
  • }

 

 

Basic HTTP server

Nginx is relatively easy to configure as a basic web server, it supports IP and Name based virtual hosts, and it uses a pcre based URI processing system. Configuring static hosting is very easy, you just specify a new server block:

 

 

  • server {
  • listen 10.10.10.100:80;
  • server_name www.foocorp.com foocorp.com;
  • access_log logs/foocorp.com.log main;
  • location / {
  • index index.html index.htm;
  • root /var/www/static/foocorp.com/htdocs;
  • }
  • }

 

 

Here we are listening on port 80 on 10.10.10.100, with name virtual hosting using www.foocorp.com and foocorp.com. The server_name option also supports wildcards, so you can specify *.foocorp.com and have it handled by the configuration. The usual access logs, and root specifies htdocs. If you have a large number of name virtual hosts, you’ll need to increase the size of the hash bucket with server_names_hash_bucket_size 128;

 

Gzip compression

Nginx like many other web servers, can compress content using gzip.

 

 

  • gzip on;
  • gzip_min_length 1100;
  • gzip_buffers 4 8k;
  • gzip_types text/plain text/html text/css text/js;

 

 

Here Nginx allows you to enable gzip, specify a minimum length to compress, buffers and the mime types that Nginx will compress. Gzip compression is supported by all modern browsers.

 

HTTP Load Balancing

Nginx can be used a simple HTTP load balancer, in this configuration, you would place Nginx in front of your existing web servers. The existing web servers can be running Nginx as well. In HTTP load balancer mode, you simply need to add an upstream block to the configuration :

 

 

  • upstream a.serverpool.foocorp.com {
  • server 10.80.10.10:80;
  • server 10.80.10.20:80;
  • server 10.80.10.30:80;
  • }
  • upstream b.serverpool.foocorp.com {
  • server 10.80.20.10:80;
  • server 10.80.20.20:80;
  • server 10.80.20.30:80;
  • }

 

 

Then in the server block, you add the line:

 

 

  • proxy_pass http://a.serverpool.foocorp.com;

 

 

Health Check Limitations

Nginx has only simple load balancing capabilities. It doesn’t have health checking capabilities and it uses a simple load balancing algorithm. However, Nginx is a relatively new project, so one would expect to see various load balancing algorithms and health checking support added over time. While it might not be wise to replace your commercial load balancer with Nginx anytime soon, Nginx is almost there in terms of a very competitive solution. Monit, and other monitoring applications offer good options to compensate for a lack of health checking capabilities in Nginx.

 

Global Server Load Balancing

Nginx has a very interesting capability. With a little configuration can provide Global Server Load Balancing. Now Global Server Load Balancing (GSLB) is a feature you’ll find on high-end load balancing switches such as those from F5, Radware, Nortel, Cisco etc. Typically GSLB is an additional license you have to purchase for a few thousand dollars, on top of a switch that typically start around US$10,000.

 

GSLB works by having multiple sites distributed around the world, so you might have a site in Europe, a site in Asia and a site in North America. Normally, you would direct traffic by region by using different top level domains (TLD). So www.foocorp.com might go to North America, www.foocorp.co.uk to Europe, www.foocorp.com.cn to the server in Asia. This isn’t a very effective solution because it relies on the user to visit the proper domain. A user in Asia, might see a print advertisement for the North American market, hitting the .com address means they aren’t visiting the closest and fastest server.

 

GSLB works by looking at the source IP address of the request, and then determines which site is closest to that source address. The simplest method is to break the Internet address space down per region, then to route
traffic to the local site in that region. When we say region, we mean – North America, South America, EMEA (Europe, Middle East and Africa) and APAC (Asia-Pacific).

 

Configuring Nginx for GSLB

The geo {} block is used to configure GSLB in Nginx, the geo block causes Nginx to look at the source IP, and set a variable based on the configuration. The nice thing with Nginx is that you can set a default.

 

 

  • geo $gslb {
  • default na;
  • include conf/gslb.conf
  • }

 

 

Here in our configuration, we’re setting the default to na (North America) and then including the gslb.conf. The configuration file gslb.conf is a basic file consisting of subnet variable. Here is an excerpt from gslb.conf:

 

 

  • 32.0.0.0/8 emea;
  • 41.0.0.0/8 emea;
  • 43.0.0.0/8 apac;

 

 

When Nginx receives a request from a source IP in 32.0.0.0/8 (for those of you unfamiliar with slash notation, this is the entire Class A, 32.0.0.0 thru 32.255.255.255), it sets the variable $gslb to emea. We then use that later in the configuration to redirect.

 

Inside the location block of our server configuration in Nginx, we add a number of if statements before the proxy_pass (if used) statement. These instruct the server to do a HTTP 302 Redirect (temporary redirect).

 

 

  • if ($gslb = emea) {
  • rewrite ^(.*) http://europe.foocorp.com$1 redirect;
  • }
  • if ($gslb = apac) {
  • rewrite ^(.*) http://asia.foocorp.com$1 redirect;
  • }

 

 

These are configured under the www.foocorp.com named virtual server, if someone from North America hits www.foocorp.com, it hits the default and simply loads from the same server. If the user is from Europe, the request should match one of the subnets listed in gslb.conf, and sets the gslb variable to emea. This request causes the North American site hosting the .com domain to redirect the client to the server(s) at the site in Europe.

 

On the European server, the configuration is slightly different. Instead of the emea check, you check for NA and redirect to the US site. This is to handle the situation when someone in North America hits the .eu or .co.uk site.

 

 

  • if ($gslb = na) {
  • rewrite ^(.*) http://www.foocorp.com$1 redirect;
  • }

 

 

Traffic Control: In-region not always faster

The problem with commercial solutions is that they are too generalized. In our example configurations so far, we make some pretty wild assumptions. The problem with the Internet is that a user in Asia, might not for example, have a faster connection to servers in Asia. A good example of this is India and Pakistan. A server hosted in Hong Kong or Singapore, is in Asia, and would be considered “in region” for customers in India and Pakistan. The reality though is that traffic from those countries to Hong Kong, is actually routed through Europe, so packets from India to Hong Kong, go from India thru Europe, across the United States and hit Hong Kong from the Pacific. However, in the same subnet, customers in Australia are only a few hops away from Hong Kong.

 

In such a situation, with commercial solutions, you are just out of luck, but with Nginx you can fine tune how traffic is directed. Here we know 120.0.0.0/6 is mainly APAC, but 122.162.0.0/16 and 122.163.0.0/16 have faster connections to Europe. So, we simply add these subnets to the configuration. Nginx will use the closest match to the source IP. So 122.162.0.0/16 is
finer grained than 120.0.0.0/6, so Nginx will use it.

 

Manual Tuning

The initial tuning can be done by using the whois command, for example whois 120.0.0.0 will give you an idea which region it belongs to – ARIN, RIPE, etc. ARIN, RIP, APNIC, AFRINIC, and LACNIC are regional internet registries or RIR. An RIR is an organization overseeing the allocation and registration of Internet number resources within a particular region of the world. IP addresses both IPv4 and IPv6 are managed by these RIRs. However, as in our previous example, you’re going to need to fine tune the gslb configuration with traceroute and ping information. Probably the best approach is to do a general configuration and then fine tune the configuration based on feedback from customers.

 

Cost Savings vs. Features

Looking at a well known Layer 4-7 switching solution, you would need a minimum of $15k per site to purchase the necessary equipment and licensing. Commercial solutions do have some additional fault tolerant measures, such as the ability to measure load and availability of servers at remote sites. However, with Nginx offering a very close solution which is available for FREE with the source code, it is only a matter of time before such features are part of Nginx or available thru other projects.

 

gslb.conf

The following is an initial example of gslb.conf, it should be sufficient for most users.

 

 

  • 25.0.0.0/8 uk;
  • 32.0.0.0/8 emea;
  • 41.0.0.0/8 emea;
  • 43.0.0.0/8 apac;
  • 51.0.0.0/8 uk;
  • 53.0.0.0/8 emea;
  • 57.0.0.0/8 emea;
  • 58.0.0.0/8 apac;
  • 59.0.0.0/8 apac;
  • 60.0.0.0/8 apac;
  • 61.0.0.0/8 apac;
  • 62.0.0.0/8 emea;
  • 77.0.0.0/8 emea;
  • 78.0.0.0/7 emea;
  • 80.0.0.0/5 emea;
  • 88.0.0.0/6 emea;
  • 90.192.0.0/11 uk;
  • 91.104.0.0/13 uk;
  • 91.125.0.0/16 uk;
  • 92.0.0.0/8 emea;
  • 93.0.0.0/8 emea;
  • 116.0.0.0/6 apac;
  • 120.0.0.0/6 apac;
  • 122.162.0.0/16 uk;
  • 122.163.0.0/16 uk;
  • 124.0.0.0/7 apac;
  • 126.0.0.0/8 apac;
  • 129.0.0.0/8 emea;
  • 130.0.0.0/8 emea;
  • 131.0.0.0/8 emea;
  • 133.0.0.0/8 apac;
  • 134.0.0.0/8 emea;
  • 139.0.0.0/8 emea;
  • 141.0.0.0/8 emea;
  • 145.0.0.0/8 emea;
  • 150.0.0.0/8 apac;
  • 151.0.0.0/8 emea;
  • 157.0.0.0/8 apac;
  • 162.0.0.0/8 emea;
  • 163.0.0.0/8 emea;
  • 164.0.0.0/8 emea;
  • 171.0.0.0/8 emea;
  • 188.0.0.0/8 emea;
  • 193.0.0.0/8 emea;
  • 194.0.0.0/8 emea;
  • 195.0.0.0/8 emea;
  • 196.0.0.0/8 emea;
  • 202.0.0.0/7 apac;
  • 210.0.0.0/7 apac;
  • 212.0.0.0/7 emea;
  • 217.0.0.0/8 emea;
  • 218.0.0.0/6 apac;
  • 219.0.0.0/8 apac;
  • 220.0.0.0/7 apac;
  • 222.0.0.0/8 apac;

 

 

How to find the no of cpu, core and if its under HT technology CPU

Finding Physical Processors

$ grep ‘physical id’ /proc/cpuinfo | sort | uniq | wc -l

Finding Virtual Processors

$ grep ^processor /proc/cpuinfo | wc -l

Finding CPU cores

$ grep ‘cpu cores’ /proc/cpuinfo

“2” indicates the two physical processors are dual-core, resulting in 4 virtual processors.

If “1” was returned, the two physical processors are single-core.

If the processors are single-core, and the number of virtual processors is greater than the number of physical processors, the CPUs are using hyper-threading.

Health Tips for keeping healthy heart. :-)

A chat with Dr.Devi Shetty ,

Narayana Hrudayalaya

( Heart Specialist) Bangalore was arranged by WIPRO for its employees . The transcript of the chat is given below. Useful for everyone.

Qn: What are the thumb rules for a layman to take care of his heart ?

Ans:
1. Diet – Less of carbohydrate, more of protein, less oil
2. Exercise – Half an hour’s walk, at least five days a week; avoid lifts and avoid sitting for a longtime
3. Quit smoking
4. Control weight
5. Control blood pressure and sugar

Qn: Is eating non-veg food (fish) good for the heart?

Ans: No

Qn: It’s still a grave shock to hear that some apparently healthy person
gets a cardiac arrest. How do we understand it in perspective?

Ans: This is called silent attack; that is why we recommend everyone past the age of 30 to undergo routine health checkups.

Qn: Are heart diseases hereditary?

Ans: Yes
Qn: What are the ways in which the heart is stressed? What practices do you suggest to de-stress?

Ans: Change your attitude towards life. Do not look for perfection in everything in life.

Qn: Is walking better than jogging or is more intensive exercise required to keep a healthy heart?

Ans: Walking is better than jogging since jogging leads to early fatigue and injury to joints .

Qn: You have done so much for the poor and needy. What has inspired you to do so?

Ans: Mother Theresa , who was my patient.

Qn: Can people with low blood pressure suffer heart diseases?

Ans: Extremely rare

Qn: Does cholesterol accumulates right from an early age

(I’m currently only 22) or do you have to worry about it only after you are above 30 years of age?

Ans: Cholesterol accumulates from childhood.

Qn: How do irregular eating habits affect the heart ?

Ans: You tend to eat junk food when the habits are irregular and your body’s enzyme release for digestion gets confused.

Qn: How can I control cholesterol content without using medicines?

Ans: Control diet, walk and eat walnut.

Qn: Can yoga prevent heart ailments?

Ans: Yoga helps.

Qn: Which is the best and worst food for the heart?

Ans: Fruits and vegetables are the best and the worst is oil.

Qn: Which oil is better – groundnut, sunflower, olive?

Ans: All oils are bad .

Qn: What is the routine checkup one should go through? Is there any specific test?

Ans: Routine blood test to ensure sugar, cholesterol is ok. Check BP, Treadmill test after an echo.

Qn: What are the first aid steps to be taken on a heart attack?

Ans: Help the person into a sleeping position , place an aspirin tablet under the tongue with a sorbitrate tablet if available, and rush him to a coronary care unit since the maximum casualty takes place within the first hour.

Qn: How do you differentiate between pain caused by a heart attack and that caused due to gastric trouble?

Ans: Extremely difficult without ECG.

Qn: What is the main cause of a steep increase in heart problems amongst youngsters? I see people of about 30-40 yrs of age having heart attacks and serious heart problems.

Ans: Increased awareness has increased incidents. Also, edentary lifestyles, smoking, junk food, lack of exercise in a country where people are genetically three times more vulnerable for heart attacks than Europeans and Americans.

Qn: Is it possible for a person to have BP outside the normal range of 120/80 and yet be perfectly healthy?

Ans: Yes.

Qn: Marriages within close relatives can lead to heart problems for the child. Is it true?

Ans : Yes, co-sanguinity leads to congenital abnormalities and you may not have a software engineer as a child

Qn: Many of us have an irregular daily routine and many a times we have to stay late nights in office. Does this affect our heart ? What precautions would you recommend?

Ans : When you are young, nature protects you against all these irregularities. However, as you grow older, respect the biological clock.

Qn: Will taking anti-hypertensive drugs cause some other complications (short / long term)?

Ans : Yes, most drugs have some side effects. However, modern anti-hypertensive drugs are extremely safe.

Qn: Will consuming more coffee/tea lead to heart attacks?

Ans : No.

Qn: Are asthma patients more prone to heart disease?

Ans : No.

Qn: How would you define junk food?

Ans : Fried food like Kentucky , McDonalds , samosas, and even masala dosas.

Qn: You mentioned that Indians are three times more vulnerable. What is the reason for this, as Europeans and Americans also eat a lot of junk food?

Ans: Every race is vulnerable to some disease and unfortunately, Indians are vulnerable for the most expensive disease.

Qn: Does consuming bananas help reduce hypertension?

Ans : No.

Qn: Can a person help himself during a heart attack (Because we see a lot of forwarded emails on this)?

Ans : Yes. Lie down comfortably and put an aspirin tablet of any description under the tongue and ask someone to take you to the nearest coronary care unit without any delay and do not wait for the ambulance since most of the time, the ambulance does not turn up.

Qn: Do, in any way, low white blood cells and low hemoglobin count lead to heart problems?

Ans : No. But it is ideal to have normal hemoglobin level to increase your exercise capacity.

Qn: Sometimes, due to the hectic schedule we are not able to exercise. So, does walking while doing daily chores at home or climbing the stairs in the house, work as a substitute for exercise?

Ans : Certainly. Avoid sitting continuously for more than half an hour and even the act of getting out of the chair and going to another chair and sitting helps a lot.

Qn: Is there a relation between heart problems and blood sugar?

Ans: Yes. A strong relationship since diabetics are more vulnerable to heart attacks than non-diabetics.

Qn: What are the things one needs to take care of after a heart operation?

Ans : Diet, exercise, drugs on time , Control cholesterol, BP, weight.

Qn: Are people working on night shifts more vulnerable to heart disease when compared to day shift workers?

Ans : No.

Qn: What are the modern anti-hypertensive drugs?

Ans : There are hundreds of drugs and your doctor will chose the right combination for your problem, but my suggestion is to avoid the drugs and go for natural ways of controlling blood pressure by walk, diet to
reduce weight and changing attitudes towards lifestyles.

Qn: Does dispirin or similar headache pills increase the risk of heart attacks?

Ans : No.

Qn: Why is the rate of heart attacks more in men than in women?

Ans : Nature protects women till the age of 45.

Qn: How can one keep the heart in a good condition?

Ans : Eat a healthy diet, avoid junk food, exercise everyday, do not smoke and, go for health checkup s if you are past the age of 30 ( once in six months recommended)…