Fixing CPU hog issue in RunUO2 RC1 with dual cpu/core

Anything regarding UO or Age of Valor
Locked
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

Fixing CPU hog issue in RunUO2 RC1 with dual cpu/core

Post by Red Squirrel »

When using RunUO on a dual core machine, it will hog the CPU, this will cause lot of lag if a lot is going on in game. To solve this, you need to do a core edit.

Open main.cs and find this code:

Code: Select all

				while ( !m_Closing ) {
														
					Thread.Sleep( m_MultiProcessor ? 0 : 1 );		

					Mobile.ProcessDeltaQueue();
					Item.ProcessDeltaQueue();

					Timer.Slice();
					m_MessagePump.Slice();

					NetState.FlushAll();
					NetState.ProcessDisposedQueue();

					if ( Slice != null )
						Slice();

					if ( ( ++sample % sampleInterval ) == 0 ) {
						now = DateTime.Now;
						m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] =
							ticksPerSecond / ( now.Ticks - last.Ticks );
						last = now;
					}
				}

This is in the main() function and is basically the main loop of the entire server. You'll notice this line:

Thread.Sleep( m_MultiProcessor ? 0 : 1 );

It makes the loop sleep for 1 miliseconds (I think, not sure the units that function uses)

Basically, any long running loop needs such delay or it will choke the application. But notice the ? 0 : 1 part. This makes it so it sleeps for 0 units if its a multi processor machine. this is BAAAAD. This will bog down the entire system including runuo itself.

Replace that whole line with:

Thread.Sleep(1);

Recompile the core, ensure to delete the scripts.cs.dll in the scripts/output folder, open the newly compiled core, and it will no longer be laggy.

Archived topic from AOV, old topic ID:1437, old post ID:8987
Honk if you love Jesus, text if you want to meet Him!
Locked