Welcome to my blog, hope you enjoy reading
RSS

Wednesday, 9 October 2013

MYSQL: ERROR 1040: TOO MANY CONNECTIONS

MYSQL: ERROR 1040: TOO MANY CONNECTIONS


If you run a fairly busy and/or badly configured MySQL server, you may receive something like this when attempting to connect:

# mysql
ERROR 1040: Too many connections
MySQL is telling you that it is handling the maximum connections that you have configured it to handle. By default, MySQL will handle 100 connections simultaneously. This is very similar to the situation when Apache reaches the MaxClients setting. You won’t even be able to connect to MySQL to find out what is causing the connections to be used up, so you will be forced to restart the MySQL daemon to troubleshoot the issue.

What causes MySQL to run out of connections? Here’s a list of reasons that may cause MySQL to run out of available connections, listed in order of what you should check:

Bad MySQL configuration
Verify that you have set MySQL’s buffers and caches to appropriate levels for the type of data you’re storing and the types of queries that you are running. One quick way to check this information is via MySQLTuner. The script will tell you how well your server is performing along with the corrections you should make. Running the script only takes a few moments and it doesn’t require a DBA to decipher the results.

Data storage techniques
Remember that MySQL works best when moving vertically, not horizontally. If you have a table with 20 columns, breaking it into two tables with 10 columns each will improve performance. Even if you need to join the two tables together to get your data, it will still perform at a higher level. Also, use the right data types for the right data. If you’re storing an integer only, don’t use a CHAR or VARCHAR data type. If your integer will be small, then use something like a TINYINT or SMALLINT rather than INT. This means MySQL will use less memory, pull less data from the disk, and have higher performing joins.

Slow queries
These are generally pretty easy to fix. If you have queries that don’t use indexes, or if queries run slowly with indexes in place, you need to rethink how you’re pulling your data. Should your data be split into multiple tables? Are you pulling more data than you need? Keep these questions in mind, enable the slow query log, and re-work your queries to find where the bottlenecks occur.

Division of labor
Most people who use MySQL have a dynamic site written in a scripting language, like PHP, Perl or Python. It’s obvious that your server will need to do some work to parse the scripts, send data back to the client, and communicate with MySQL. If you find that your server is overworked, consider moving MySQL to its own dedicated hardware. Among many other things, this will reduce your disk I/O, allow you to better utilize memory, and it will help you when you need to scale even further. Be sure to keep your MySQL server close to your web servers, however, as increased latency will only make your performance problem first.

Right hardware
Do you have the right hardware for the job? Depending on your budget, you may need to make the move for hardware that gives you better I/O throughput and more useable cores. MySQL is a multi-threaded application, so it can utilize multiple cores to serve data quickly. Also, writing logs, reading tables, and adjusting indexes are disk-intensive tasks that need fast drives to perform well. When you look for a dedicated server for MySQL, be sure to choose multiple-core machines with low latency RAM, fast drives (SCSI/SAS), and a reliable network interface.

By reviewing these bottlenecks, you can reduce the load on your MySQL server without increasing your maximum connections. Simply increasing the maximum connections is a very bad idea. This can cause MySQL to consume unnecessary resources on your server and it may lead to an unstable system (crash!).
Share

Wednesday, 2 October 2013

Get all Request Parameters in Servlet

Get all Request Parameters in Servlet


  • Use HttpServletRequest.getParameterNames to get an Enumeration of parameter names.
  • Use HttpServletRequest.getParameterValues(paramName) to get the parameters values.

package com.javanotes2all.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GetAllRequestParametersInServlet extends HttpServlet {

private static final long serialVersionUID = -2128122335811219481L;

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
handleRequest(req, res);
}

public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
handleRequest(req, res);
}

public void handleRequest(HttpServletRequest req, HttpServletResponse res) throws IOException {

PrintWriter out = res.getWriter();
res.setContentType("text/plain");

Enumeration<String> parameterNames = req.getParameterNames();

while (parameterNames.hasMoreElements()) {

String paramName = parameterNames.nextElement();
out.write(paramName);
out.write("n");

String[] paramValues = req.getParameterValues(paramName);
for (int i = 0; i < paramValues.length; i++) {
String paramValue = paramValues[i];
out.write("t" + paramValue);
out.write("n");
}

}

out.close();

}

}
Share

Tuesday, 1 October 2013

css class attributes inside of struts html tags

css class attributes inside of struts html tags

<html:text property="ssn" class="textfield2" />
this is not applying style

the following attribute is applying style
<html:text styleClass="textfield2"/>
Share

Thursday, 19 September 2013

Setting the PATH and CLASSPATH on Windows

For VERSION 1.5.0_02 of Java (new version)

 1.      Click on START (lower left)

2.      Under "Settings" click on "Control Panel"

3.      Switch to "classic view" (upper left) -- not "category view"

4.      Click on the "System" icon.

5.      Click on the "Advanced" tab.

6.      Click on the "Environment Variables" button (bottom).

7.      Highlight "PATH" (in the top window) and click the "edit" button.

NOTE:  DON'T EDIT OR MODIFY AND OF THE "SYSTEM VARIABLES" -- you could render your entire computer unusable! --

8.      Edit the "PATH" so it begins C:\Program Files\Java\jdk1.5.0_02\bin; (note: if you install Java into a different directory, you may need to change the directory from that listed above)

9.  After you have finished editing the PATH, click "OK".  You are done setting your PATH.  Now you have to create a new variable, called your CLASSPATH.

10.  Click on the "NEW" button below the top window.

11.  Under 'variable name' type CLASSPATH

12.  Under 'variable value' type . (yes, type a single period).

13.  Click OK.

14.  EXIT the control panel.

15.  Restart your computer.

16.  Test your installation by opening up a DOS window and verifying that both the commands "java" and "javac" are recognized.
Share

Thursday, 29 August 2013

How to increase mysql connections

How to increase mysql connections

If you are getting “too many connections” errors in MySQL. By default the max_connections is 100, you need to change the max_connections to allow more connections, you will need to have enough RAM/memory to handle the increased number.
Share

Eclipse ADT update does not work

Eclipse ADT update does not work

Problem:
I updated my android sdk to and I tried updating my adt via ecplise through
Help-> Check for updates.
This action results in the dialog that says -
'no updates found'
But my sdk says-
This android is SDK requires Android Development Kit 21.1.0 or above
  Current version is 21.1.0.v201212060256-543035.

Share

Monday, 26 August 2013

Data Types in java

Data Types in java


Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables.
There are two data types available in Java:
  • Primitive Data Types
  • Reference/Object Data Types
Share

How To See the Processor Model Number/Speed on Linux

If you rely on somebody else for managed hosting of your Linux servers, you might not always know exactly what type of server you’re actually running on. There’s a quick and easy way to figure this out, however.

Simply type in the following command at the prompt:

cat /proc/cpuinfo
And then you’ll see a big long list of all the processor in the system, along with all the information about them, which should look something like this:
output:
-------------------------------------------------------------------------------------
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 26
model name      : Intel(R) Xeon(R) CPU           L5520  @ 2.27GHz
stepping        : 5
cpu MHz         : 2267.545
cache size      : 8192 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
 mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe
nx rdtscp lm constant_tsc pni monitor ds_cpl est tm2 xtpr popcnt
bogomips        : 4538.12
-----------------------------------------------------------------------

You’ll see in this example that we’re running on an Intel Xeon L5520 running at 2.27GHz… and if we had shown the full example you’d see that there are actually 4 cores on the machine.
Share

Thursday, 22 August 2013

Upgrade to 12.04 in ubuntu stuck

Upgrade to 12.04 in ubuntu stuck

This time the crash is quiet. Nothing is happening. The screen displays the following and the disk light occasionally blinks but there is no progress indicated on the screen.
Share

Saturday, 3 August 2013

What svn revision was this branch created in?

What svn revision was this branch created in?

how do I find out in which svn revision a branch was created?

The answer is 
svn command: to show all the log from creating the branch.

svn log --stop-on-copy  url (url of the branch).

Share