Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System.Threading.Timers on multiprocessor Windows Server 2003

83 views
Skip to first unread message

Jamus

unread,
Apr 19, 2005, 10:52:31 PM4/19/05
to
Wasn't totally sure if this was the right newsgroup to post to, so if
there's a better place, please let me know.

Windows Server 2003 (multiprocessor) seems to have a curious
implementation of System.Threading.Timers.

The abnormal behavior became obvious when we upgraded from Windows
Server 2000 to Windows Server 2003. A section of our code used a large
number of System.Threading.Timers to schedule methods for later
execution.

While on 2000 there was no problem, on 2003 we began to notice that at
a certain point the timers would begin firing erratically and then
cease to fire at all after the application (C#, .NET 1.1 SP1) had been
executing for a while.

Artificially increasing the rate at which these timers were created
resulted in reproducing the error faster. The problem does NOT occur
on Windows 2000 Server, or on any other version of Windows that we've
tested!

We created a small testing application (Very simple source below) which
schedules 30,000 timers at once, and then counts how many of them fire.
When running on any version of windows other than 2003, 100% of the
timers fire 100% of the time. On two Windows 2003 machines with
multiple processors (AMD on one, Intel on the other) a variable number
of the timers actually fired-- sometimes all 30k, sometimes 29k,
sometimes 27, 24, or even <20k. On two Windows 2003 machines with
single processors, 100% of the timers fire 100% of the time.

Running the test process in multiple instances concurrently results in
far fewer of them reaching completion, and in the tests terminating
early (more failed callouts.) Running dummy applications which do
garbage calculations to simulate high CPU load caused similar behavior.

No exceptions are thrown. Memory, according to Task Manager, is not
low.

Anyone have any ideas why Windows Server 2003 seems to behave so
erratically?

The test application code follows:

using System;
using System.Threading;
using System.Collections;

namespace CountCallOuts
{
class MainDriver
{
public static int CallCount=0; //Number of times the timer method is
executed.
public static object Locker=new object(); //Dummy object for
lock()ing.

[STAThread]
static void Main(string[] args)
{
//Create TimerCallback delegate
System.Threading.TimerCallback timercallback = new
System.Threading.TimerCallback(MainDriver.IncrementAndDisplay);

//For maintaining references to the timers in case GC is an issue
ArrayList TimerList= new ArrayList();
//To prevent the timer methods from doing any work before they are
all scheduled.
lock(Locker)
{
System.Console.WriteLine("Creating timers...");
for(int x=0;x<30000;x++)
{
TimerList.Add(new System.Threading.Timer(timercallback, null,
5000, Timeout.Infinite));
}
System.Console.WriteLine("Done queuing.");

}
//To keep console window open indefinitely
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);

}
public static void IncrementAndDisplay(object stateinfo)
{
//This lock is in place so that the outputs reach the screen in
order, 1, 2, 3...
lock(Locker)
{
CallCount++;
System.Console.WriteLine("IncrementAndDisplay called: "+
(CallCount));
}
}
}
}

Jamus
jamuspsi at earth link net

Declercq Dirk

unread,
Apr 20, 2005, 3:39:33 PM4/20/05
to
We have encountered the same problem with our application after
installing the SP1 on Windows Server 2003.
Deinstalling the SP1 removed the problem.

In our code our timer cease firing his events after about 2 hours.

/// <summary>
/// Timer object, generates OnTimer() events based upon m_Timebase.
/// </summary>
[NonSerialized]
private Timer m_Timer;


/// <summary>
/// Starting the timer
/// </summary>
private void SomeMethod()
{
if ( m_Timer == null )
m_Timer = new Timer( new TimerCallback( Timer ), this,
Timeout.Infinite, Timeout.Infinite );
}

/// <summary>
/// Timer delegate.
/// </summary>
static private void Timer( object Object )
{
// After about 2 hours this code is no more called
((Mover)Object).m_TimerEvent.Set();
}

Jamus

unread,
Apr 22, 2005, 12:50:17 AM4/22/05
to
Unfortunately, we have already uninstalled the Service Pack, but still
get the problem...

But our install and uninstall of SP1 both had errors...

Very difficult to reinstall 2003 altogether because all work is done
remotely (2000+ miles away!)

Anyone have any ideas of how to restore the system to the state it had
before SP1?

0 new messages