What is your operating system? Usermode apps do not cooperate in CPU scheduling.
Main Topics
Browse All TopicsI have a Webapplication with Java and Hibernate using a Postgres DB.
On my server are two apps running:
1. The Webapplication
2. An Import for the Webapplication, also with Java and Hibernate
both are using the same Postgres DB.
The problem is that while the import is running, postgres consumes 100 % CPU and the Webapp is to slow. How can I specify that the Postgres activities of the import-app should not consume all the CPU, so that the web-app can work fast?
Thanks in advance.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Are you sure the system is CPU bound? The most common problem with database performance is I/O, in which case you will probably see high I/O wait times (the %wa column if you're using top to watch system performance).
If the problem's I/O, there are many articles on tuning postgres for performance.
If the problem's truly CPU, you'll find fewer resources. However, check to ensure the import application is using prepared queries to eliminate the planning phase on the backend.
Usual problem scenario is that you are out of memory and both programms attempt to use swap and that slows down rest of IO in system as it goes at maximum priority.
Uptime 10..100 can be observed at that time.
Solution - restrict program's memory usage like -server -Xmx for Java or use some pooling proxy for Postgresql do that less connection serving processes run routinely.
Hi,
You could make use of 'nice' which manipulates process priority. The higher the nice value, the lower it's priority, the less nice it is (per se), the higher priority it will run with.
Simply give your postgresql a higher niceness than your webapp.
Man page:
http://linux.about.com/lib
Little article on using nice:
http://blogs.techrepublic.
HTH.
Sorry for answering so late. We had another urgent task.
@gheist
Our operationg system is Ubuntu 8.04
@hfraser
I couldn't recreate the same situation with 100% CPU, but I have attached a snippet of vmstat of the next import.
You were right, the high values come from wa.
>>If the problem's I/O, there are many articles on tuning postgres for performance.
The only effect of tuning postgres is that the import would be faster. But what I'm aiming at, is that the import app must not consume so much ressources.
@gheist
>>Usual problem scenario is that you are out of memory and both programms attempt to use swap and that slows down >>rest of IO in system as it goes at maximum priority.
>>Uptime 10..100 can be observed at that time.
I didn't figure out that point completely. How can I determine that the swaps are the problem?
@stephenhoeks&
If I would nice postgres I would also make my Wepapp slower, but I only want to nice the postgres processes which come from the import-app. Is there a possibility that postgres knows from which app the query comes and therefore consumes either more or less ressources. But looking at the posting of woolmilkporc, the nice-approach seems not to work anyway.
@earthman2
Yes hardware is cheap, but we are a small company and budget is low. But we've already planned that for the future.
@gheist
Here ist the memory situation. I know, that only 134 MB are left, but as I learned so far that the cached 918 MB is also available, so everything should be OK. Please correct me if I'm not right.
# free -m
total used free shared buffers cached
Mem: 3986 3851 134 0 1 918
-/+ buffers/cache: 2931 1055
Swap: 8197 85 8111
@gheist
I've attached the memory consumption on our server. Actually we have 3 wepapps, but that wasn't important so far.
So if I understand you right, I should reduce the Xmx values to say 600m, because I think I may not reduce the value under the RSS value. Looking at the VSZ value I wonder why that process may consume over 1 GB even if only 800 MB are allowed.
You said the problem is the swapping (line 13), but the the high wa-values are from line 17 to 25. Does that fit?
That fits perfectly. IO is counted and then swap pages are commited to disk and system is lazy while it waits for memory management operation to complete.
Java memory management is describet alongside -XX options. BTW is your system 32bit or 64bit?
Do you have any real need to exceed 256mb od -Xmx by overriding default value? Like OOM when running webapp.
What is your application server? Why you do not run all your "webapps" inside single server?
The 4 java processes together only appear to be using about 40% of the memory, and each appears to consuming about the same amount of memory, which to me doesn't look like any of them were swapped out. It's possible some other apps on the system were swappped that caused the "so" spike when the import started.
There's definitely a lot of wait state, presumably after the import begins, which isn't unexpected. You might want to check how the import's done, especially concerning locks on the table that might be there to speed the import.
Sorry. I didn't mean to suggest there isn't swapping happening, or that more memory won't help (it always does). But there are only two major swap events: at 13 (swap out) and 33 (swap in). The "ps aux" command doesn't seem to indicate either of them related to his java apps, and the high I/O wait activity would indicate the system is waiting on disk, which I'd presume is the import process.reading and postgres reading/writing. It's highly likely that everything unrelated has been swapped out, but they might be bash, X, gnome/kde, etc. which won't affect his web apps.
It's also possible that the import process does something very intrusive, like table locks, to improve the update process speed, but at the expense of db clients.
It's all speculation, of course, since I don't know what got swapped out. Checking for processes with a RSZ of 0 and a high VSZ will show what got swapped out.
My point is just that there might be more than swapping affecting the web app's performance.
Having said that, I have a couple of machines that are pure app servers (one is a db server), and I always disable X to conserve memory (start them at runlevel 3). Disabling them for a test is certainly easier and quicker than re-writing the import code, and would be my first thing to try.
I'll let the postgresql documentation elucidate those ext3 options...
Tip: Because WAL restores database file contents after a crash, journaled filesystems are not necessary for reliable storage of the data files or WAL files. In fact, journaling overhead can reduce performance, especially if journaling causes file system data to be flushed to disk. Fortunately, data flushing during journaling can often be disabled with a filesystem mount option, e.g. data=writeback on a Linux ext3 file system. Journaled file systems do improve boot speed after a crash.
Another tip is:
It is of advantage if the write ahead log WAL is located on another disk than the main database files. This can be achieved by moving the directory pg_xlog to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.
I find the modifications with the filesystem very interesting but to risky on our online server. I finally improved the import script so that the high don't last so long.
For me it was important to find out that the IO (wait value) was the problem and that it makes no sense to make a postgres process nice.
P.S:
We have a ext3 filesystem and also a software RAID 1. That could possibly explain the high wa values.
Business Accounts
Answer for Membership
by: woolmilkporcPosted on 2009-03-17 at 01:59:12ID: 23905743
Hi,
here is an interesting thread on that theme.
Basically, it says that renicing a backend was "somewhere between useless and counterproductive for most query loads."
http://bytes.com/gr
wmp