Solved

threading issue using java?

Posted on 2013-06-03
3
403 Views
Last Modified: 2013-06-10
We have a java application that' running in a linux centos.

I think there's a java app design flaw - I've allocated 2 CPU and 4 CPU and the Java application seems to only consume a weight of 10 queries per second and it will bog down. This means it doesn't matter how much memory and cpu I allocate - it will slow down as the algorithm can't take it.

Fact.
1. I have 2 cpu allocated and each one is utilizing 50%  => the Java  app was at 100% when watching TOP (linux)
2.  I have 4 cpu allocated and each one is utilizing 25%  => the Java  app was at 100% when watching TOP (linux)

http://snag.gy/4YHBZ.jpg


The link shows 4 CPU but the java application could not utilized all 4 CPU with 100% each? I don't have the source code but would like to inquire from the experts on how do you think this is and how can we have each core to utilize 100%?
0
Comment
Question by:gsmith888
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
phoffric earned 400 total points
ID: 39217991
You should look at your code and see how many threads are designed to run, and how much contention there is associated with synchronization, with query locks if DB is involved, with disk I/O, with caching, and with shared memory data. Even if multiple threads are just reading the same shared memory, a CPU core can stall while waiting for access, and in this case the CPU utilization will rise even though the stalled core is not doing anything useful. If you can provide the code, we may be able to better assist you.

Here's a quote from this link: http://www.devx.com/Java/Article/35087/0/page/2 

A large part of the application server execution time is spent transmitting data back and forth across components, taking out locks, or waiting for locks to be released. Spending some quality time with a profiler can show you just how much time your application spends on these tasks, which cannot benefit from a faster CPU.
Here are additional links which discuss at length some of the issues which may be plaguing your program:
how do I optimize for multi-core
Java thread affinity
0
 
LVL 32

Expert Comment

by:phoffric
ID: 39218013
This link introduces important Java parallel application profiling tools: highly scalable java programming for multicore system

More profilers and the contention issues monitored:
http://pic.dhe.ibm.com/infocenter/isa/v4r1m0/index.jsp?topic=%2Fcom.ibm.msdk.help.isa%2Fhtml%2Fmaintopic.html
0
 
LVL 26

Assisted Solution

by:dpearson
dpearson earned 100 total points
ID: 39218066
If you're not getting full CPU utilization, the first place to look is at the database.  The vast majority of web applications are bottlenecked by database throughput, not CPU throughput since most of the work they do is retrieving data.  There's usually not a lot of complex calculations involved.

Take for example this web site - experts exchange.  Almost everything you see on the page here will live in the database.  All the web server has to do is retrieve that data, format it for HTML and send it over the network.  The only way to get a system like this to 100% CPU across multiple cores is if the database can keep up - which means looking at the number of connections that are being opened and whether they are blocking, waiting for the database to respond or not.  If this turns out to be the case, then increasing the max number of db connections may increase overall throughput and allow the CPU utilization to rise.

Doug
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to parse custom JSON to POJO java 4 76
split53 challenge 7 99
by zero exception 10 41
How to configure empty element in XML Document parser? 15 18
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question