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:

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)...

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.

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).

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...

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.

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. It's almost comical how bad VM on Windows is.

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 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.

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.

Storing on flash memory is better if you don't write too much.That memory is pretty short lived when you have to do that sort of operations. IIRC, the MTBF for each bits is around 100k writes.That makes much when you write some mp3s from time to time and pass most of the time reading them, but for a swap/HD replacement, you'd avoid it at all costs.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org