0

I'm using MySQL 5.1, Apache Tomcat 7, MyBatis 3.1

I have a method with code like this:

for( Order o : orders) {
    List<Details> list = getDetails(o);
    //Create PDF report ...
}

Where getDetails is a method that executes a stored procedure that takes some time to execute ( 1 to 2 seconds), The problem here is that I have many orders (near 4000) and I need to execute this method to process every order, and when I hit that method, the CPU usage of the MySQL process goes up to 90 - 100%

Is that normal?, Do I need to use Thread.sleep() after getDetails if executed?, Or do I need to do some modifications to my query?,

Nestor Hernandez Loli
  • 1,412
  • 3
  • 21
  • 26
  • 1
    The CPU is there to work. Unless the system is idle, there's always a component running at 100%. If it's the CPU, it only means that your HD is not the bottleneck. – maaartinus Feb 07 '14 at 19:09
  • @maaartinus Do you think so?, it's a server, how does it affects to other users connected? – Nestor Hernandez Loli Feb 07 '14 at 19:12
  • Now it makes sense. If both processes run on the same CPU and there's no free core, this could be bad. Or not. Measuring it surely helps. Giving the long running thread a lower priority could help too (so that users not needing it could be served faster). And maybe you could optimize your query... or what you store in the DB or whatever... *a long running query needed to process every order doesn't sound good*. But then we'd need the details. – maaartinus Feb 07 '14 at 19:22
  • possible duplicate of [MySQL high CPU usage](http://stackoverflow.com/questions/1282232/mysql-high-cpu-usage) – Jeremy Stein Feb 07 '14 at 20:24

0 Answers0