Need help optimizing to get rid of stutterings.

Some of you might now I’m working on a multiplayer space shooter called Xtreme Space War. (It’s in the showcase/Action section)

I need some help optimizing… have searched the forum and tried alot of things maybe I’ve missed something.

The problem is when I am running a server and a client on the same computer. After a clean reboot it works smooth. But after having run some other apps (such as Eclipse) the problem appears, and it persists even after closing all other apps.

The best I can do with tweaking flags is to get 6 stutterings of about 0.5 s each with 6 s between them in the client. After that everything runs smoothly. This is a log:

XSW logfile - version 1.0
13.28:48 C: List complete.
13.28:48 C: Test Server (LOCAL), ip=85.224.17.252, port=1253, players=0/20, pingTime=8
13.28:49 C: Connection established.
13.28:50 C: free mem: 39012056
13.28:50 C: free mem: 44990064
13.28:52 C: FrameTime: 520.2136
13.28:58 C: FrameTime: 526.26965
13.29:04 C: FrameTime: 516.5592
13.29:10 C: FrameTime: 513.2217
13.29:16 C: FrameTime: 506.33752
13.29:22 C: FrameTime: 508.01904
13.30:08 C: Server connection closed

The frame time is printed whenever it goes above 40 ms, so in between these problem frames there are alot of other < 40 ms frames.

The flags I am using are:

-XX:CompileThreshold=500
-Xmx48m -Xms48m
-XX:+UseParallelGC
-XX:MaxGCPauseMillis=10
-XX:NewSize=12m
-XX:MaxNewSize=12m
-Xloggc:gc_server.txt

I have set the memory flags pretty high so I know it is not gc causing it. I’ve watched the trace and before entering the gameloop I do a System.gc, after that there is no gc collection occuring the first 30 s… but in this time the stuttering occurs with exactly 6 s interval.

The server is run in its own vm (separate program) using the same flags, and also has no gc occuring.

So, gc should not cause this at all… something else must be doing it, I figured compilation might…

These things I have tried.

-XX:CompileThreshold (with a few different values - seems to do nothing to help the problem)
-Xbatch - same problem
-Xint - same problem but now I get a terrible frame rate (20 fps)
-Xcompile - same problem

turned off all logging (to see if IO blocking might be the issue) - same problem.

Running the client or server on their own works fine. But running both together on the same computer (my laptop) I get these problems. (Well after having the computer running for a couple of days, with alot of apps running I get some similar problems when only running the client, but haven’t tryed optimizing that yet).

I would be happy for any ideas that might help, this is really bugging me.

If you want to help by profiling it yourself let me know, and I can send you a newer version of the game (fixes alot of problems)…

My specs are:

computer: Acer TravelMate 3002
cpu: pentium mobile 1.7 ghz
ram: 2 gb
Windows XP
java 1.5 latest revision

Dump the CompileThreshold :slight_smile: Plus you might want to try using -server and see if that helps…

I have tried without compile threashold (actually didn’t use it until some tests today), but it was the same.

It’s important that it will without server vm’s as players themselves should be able to run both server and client without problem (and I don’t want to ask them to download server vm).

Anyways, tried server vm and it did not help.

thanx for the suggestions though.

use a profiler to check if theres a performance leak…
use another vm (bea jrockit), or java6

could it be the JIT optimizing the code?

Are you running J2SE 5? If so could you try upgrading to 5.0u6? There was a problem with earlier 5.0 update releases where certain threads’ priorities were being set too high which could actually interfere with other applications as well as other threads in the same application.

Now I upgraded to 5.0u6… still the same. I find it very weird that it is always at 6 seconds interval it happens, no matter what settings I use, and after 5 - 6 pauses it disappears.

I tested it just now on my older comp, which has a better graphics card, and there were no problems, it ran without any stutter even though I had several big apps running in the background.

So, maybe it wont be a problem for most people, as most doesn’t do gaming on a laptop with integrated graphics… although it would be nice to have it running smooth during development as well.

Could you please remove all of the GC-related flags? It looks like you’re setting a potentially unreachable pause time goal, and your fixing of the min and max size is defeating the GC’s ability to size the heap to the size of the working set. BTW, 48 MB is not very large; the default maximum heap size is 64 MB, so you’re actually constraining the app to run in less memory than it would otherwise have available (assuming the working set is large).

It was large compared to what I was using previously, 16 mb :wink:

I read somewhere that fixing the rate would make less stuttering because then it would avoid alot of resizing and copying. This article led me to mess with some of these parameters: http://fivedots.coe.psu.ac.th/~ad/jg/appC/index.html

Anyways, I removed all the flags… and looking at the gc logs I got even less gc… after the initial bunch of collections and after a big System.gc, the first other gc occured 50 s later.

Thanx for the tip, the gc doesn’t seem to benefit from the flags I was using at all. The same stuttering problem remains though. Every 6 seconds for a while then it dissappears. The more apps I’ve run in the background, and the longer time they’ve run seems to affect the duration before the stuttering disappears. After a clean reboot I get no stuttering at all…

Are you sure you dont have the heap set TOO large?

This sounds to me like you are encountering swapping. Watch the disk light and see if it is flickering when you get your stutters.

Could I be getting disk swaps even without any flags? I use no paging file at all (2 gb ram), can it start swapping things even though I don’t use a paging file?

Anyways, I’ll check to see if it does any swapping.

Sure.

If you are using all but 1 byte of your available memory in other programs then as soon as you use mroe then 1 byte of your heap, you start swapping.

Are you nuts? Swap file is there for reasons. One of them is freeing of memory from unnecessary drivers and other silly stuff that OS loads into memory. (It’s often 415 MB on my computer.)

Of course OS could do things like deleting tmp files, updating registers, and recording your missbehaviour into the log file. Try to start more clients and server on the same computer, and try to test it also on Linux and other configurations.

Nuts? Hoho, I’m not nuts… why free memory when I have 2 gb ram? I think windows xp does a really poor job of handling the swap file… After going to 2 gb programs would start swapping out after not being used for a little while, so I have to wait for them to swap back in even though I have loads of free memory. The reason why I upgraded ram was to get rid of the swaps, then when I noticed there was still alot of swapping I disabled the swap file and it now works like a charm. I generally have alot of applications loaded, and the day is running for several days. I want to be able to swap between the programs instantly without having to wait for them to be read from disk. I use a laptop with a pretty slow harddrive so swapping is very annoying, after disabling the page file I can instantly change program without any delay. And it has caused me no problem whatsoever…

Even when running alot of programs I seldom have less than 1 gb of memory free, so the page file really isn’t neccessary. So I don’t think I’m nuts, I just want to get the best performance possible from my computer, and without page file it is a lot faster. If the paging was implemented correctly there would be no problem… but it doesn’t seem to be done right in xp…

Anyways… when running on my wife’s desktop computer (my old one…) I don’t get the same problems. More clients will cause the same stutterings. After running the computer for many days I get stutterings while only running the client also. No other people seems to get these stuttering problems with my game though, so I’ve put investigation of the problem on ice…

Microsoft appears to have the concept of virtual memory backwards… they tend to force things into secondary storage in order to make the least use of RAM. :slight_smile: It’s almost comical how bad VM on Windows is.

agreed! That’s why I don’t use a page file ::slight_smile:

I used to turn the page file off but have since found that it’s a little better with it turned on most of the time, especially with KeepResident installed in Eclipse :slight_smile: I also use LargeSystemCache under XP which favours file IO cacheing over apps. But seeing as mostly I only ever have Titan Attacks, Eclipse and Opera running this is no bad thing.

Cas :slight_smile:

Random program failures isn’t nice thing. Just because MS is unable to create reasonable memory usage analisys, doesn’t mean swap file is the bad thing TM. Obviosly in majority of cases you will not notice absence of swap file if you have 2GB memory. However when 3 - 4 programs would go nuts, you’d have a few nice, or but ugly crashes. Or you can play a sim game, and in other thread Civ4. Crash is nearly sure without swap file.

Then again windoze on a 32 bit computer limits user space to 2GB adress space, the other 2GB is for windoze. 64 bit computers doesn’t have this ugly limit, so caching on HD will be less needed for games. (And OS without swap would guarantee crash.) Advanced AI is memory eater. 64 bit pointers are not free either.

Can’t you put the 2GB swapfile on a RAM-disk then? ;D

* Riven propably missed the point :wink:

* darkprophet thinks the whole idea of HD/Ram business will become obselete once a big enough flash disc drive is created (6Gb at the moment)

DP

* swpalmer thinks flash memory speeds are still slow compared to hard drives. Maybe the new holographic storage will help :slight_smile: