Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-29-2008, 04:11 PM
Member
 
Join Date: Aug 2008
Posts: 4
mathes_n is on a distinguished road
Performance issue
Hi,


The piece of code marked bold iterate 2000 times due the result set in table and as result the CPU utilization is hitting 100% for a 2 GB RAM Server with 4 GHZ processor.


public List retrieveCustomersForSearch() throws Exception{
List customers = null;
Session session = null;
CustomerBean customerBean = null;
Object[] resultArray = null;
try {
session = HibernateUtil.currentSession();
String SQLQuery = "SELECT name,customer_id FROM CUSTOMERS order by name";
List tempList = session.createSQLQuery(SQLQuery)
.addScalar("customer_id", Hibernate.LONG)
.addScalar("name", Hibernate.STRING)
.list();
tempList = tempList==null?new ArrayList():tempList;
customers = new ArrayList();
for (int index = 0; tempList!=null && index < tempList.size(); index++) {
resultArray = (Object[]) tempList.get(index);
customerBean = new CustomerBean();
customerBean.setCustomerId(Long.valueOf(resultArra y[0].toString()));
if(resultArray[1]!= null) {
customerBean.setName(resultArray[1].toString());
}else {
customerBean.setName(null);
}

customers.add(customerBean);
}


} catch (HibernateException he) {
log.error("caught: " + he);
throw new PersistenceException(he.getMessage(), he);
} catch (Exception e) {
e.getMessage();
throw new RuntimeException("Unable to retrive Customers from datastore: ", e);
}
return customers;
}

Is there some other way of implementation so that i can solve the issue

Please help me out

Thanks in Advance!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-29-2008, 04:46 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
Quote:
Originally Posted by mathes_n View Post
Hi,

The piece of code marked bold iterate 2000 times due the result set in table and as result the CPU utilization is hitting 100% for a 2 GB RAM Server with 4 GHZ processor.
....
Is there some other way of implementation so that i can solve the issue

Please help me out
What's the optimization goal ?
You want to decrease CPU utilization ?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-01-2008, 08:59 AM
Member
 
Join Date: Aug 2008
Posts: 4
mathes_n is on a distinguished road
Yep...Want to decrease the CPU Utilization atleast by less than 30%
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-01-2008, 09:05 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Are you sure that the 2000 iteration cause for this. Did you try it for less number of iterations? May be for 100. What happens? Better to ensure that first.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-01-2008, 10:32 AM
Member
 
Join Date: Aug 2008
Posts: 4
mathes_n is on a distinguished road
yep...if it is 100 then it bcomes only 40%
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-01-2008, 10:56 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Ok, now it's confirm. But actually even 40% is not worth. That mean rest of the code in your application also effect on this.

Anyway, now think about a best way to breakdown whole process in try block, may be into few methods. Because in a single try block you are trying to execute large number of process. Execute a query, initialize members twice and many more. It really cause to the process.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-01-2008, 03:36 PM
Member
 
Join Date: Aug 2008
Posts: 4
mathes_n is on a distinguished road
Thanks for your suggestion but even after splitting it gives the same result

My splitted code looks like

public List retrieveCustomersForSearch() throws Exception{
List customers = null;
//List tempList = null;
Session session = null;
CustomerBean customerBean = null;
Object[] resultArray = null;
try {
session = HibernateUtil.currentSession();
/*customers = session.createSQLQuery("SELECT name,customer_id FROM CUSTOMERS order by name")
.addEntity("customers", com.boeing.tsas.castle.model.CustomerBean.class).l ist();*/

String SQLQuery = "SELECT name,customer_id FROM CUSTOMERS order by name";
List tempList = session.createSQLQuery(SQLQuery)
.addScalar("customer_id", Hibernate.LONG)
.addScalar("name", Hibernate.STRING)
.list();

tempList = tempList==null?new ArrayList():tempList;
customers = customerBeanForm(tempList);
} catch (HibernateException he) {
log.error("caught: " + he);
throw new PersistenceException(he.getMessage(), he);
} catch (Exception e) {
e.printStackTrace();
e.getMessage();
throw new RuntimeException("Unable to retrive Customers from datastore: ", e);
}
return customers;
}


private List customerBeanForm(List tempList){
List customers = new ArrayList();
//Session session = null;
CustomerBean customerBean = null;
int size;
if (tempList != null && tempList.size() >0) {
size = tempList.size();
Object[] resultArray = null;
for (int index = 0; index < size; index++) {
//System.out.println("Inside before obj array ::"+new java.text.SimpleDateFormat("hh:mm:ss:SSS").format( new Date()));
resultArray = (Object[]) tempList.get(index);
//System.out.println("Inside After obj array ::"+new java.text.SimpleDateFormat("hh:mm:ss:SSS").format( new Date()));
customerBean = new CustomerBean();
customerBean.setCustomerId(Long.valueOf(resultArra y[0].toString()));
if(resultArray[1]!= null) {
customerBean.setName(resultArray[1].toString());
}else {
customerBean.setName(null);
}

customers.add(customerBean);
//System.out.println("last line in for ::"+new java.text.SimpleDateFormat("hh:mm:ss:SSS").format( new Date()));
}
}
return customers;
}
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 09-01-2008, 06:40 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
Not sure that CPU utilization could be decreased at all in this scenario. Code loads processor heavily without any yields, so...

How much time does it get to perform 2000 cycles, by the way ?

I'd understand the goal "decrease execution time from 20 secs to 5 secs", but decreasing CPU utilization itself...Well, usage of Thread.sleep(10) will give some relief to CPU but not sure that this is your real intent.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 09-02-2008, 07:11 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Can you find that how many time your tempList initialized within the try block. I mean, may in the process it can set to null and initialize again and again. Like that try all possibilities.

And also pay attention on what ProjectKaiser says about threads and stuff.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU performance getting affected peiceonly Lucene 2 10-06-2008 10:24 PM
Performance Plugin bugger Eclipse 0 01-31-2008 04:01 PM
taglibs performance issue eva Advanced Java 1 01-17-2008 02:44 PM
Performance Of Collections thomasprabu Advanced Java 0 01-05-2008 01:17 PM
how to improve the performance of JWS? dinesh kaushik Java Applets 0 11-21-2007 10:46 AM


All times are GMT +3. The time now is 05:32 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org