Queue.Dequeue () slow?

  • Thread starter Thread starter Benny Raymond
  • Start date Start date
B

Benny Raymond

It's currently taking a minimum of .2 seconds for me to dequeue an
object - I'm wondering if it's the dequeue that is taking so long or if
it's just the fact that i'm doing it like this:

retMsg = (ServerMessage)s_messages.Dequeue();

is there a faster way?
 
Benny Raymond said:
It's currently taking a minimum of .2 seconds for me to dequeue an
object - I'm wondering if it's the dequeue that is taking so long or if
it's just the fact that i'm doing it like this:

retMsg = (ServerMessage)s_messages.Dequeue();

is there a faster way?

That shouldn't take very long at all. Are you absolutely sure that line
is the issue?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
I wrote up an example program with my ServerMessage and it ran
instantly.. :( The thing is, however, in my main program I put the
following lines before and after the dequeue:

Debug.WriteLine("START DQ: " + DateTime.Now.ToString("mm:ss.fffffff"));
ServerMessage m = (ServerMessage)myQueue.Dequeue();
Debug.WriteLine("END DQ: " + DateTime.Now.ToString("mm:ss.fffffff"));

I know it's a pretty bad way to look at how long things take, but that's
how I got the .2+ second mark... Not sure why it's doing that in my main
program but not the sample one... in the sample one the time between
start and end doesn't change at all.
 
Benny said:
I wrote up an example program with my ServerMessage and it ran
instantly.. :( The thing is, however, in my main program I put the
following lines before and after the dequeue:

Debug.WriteLine("START DQ: " + DateTime.Now.ToString("mm:ss.fffffff"));
ServerMessage m = (ServerMessage)myQueue.Dequeue();
Debug.WriteLine("END DQ: " + DateTime.Now.ToString("mm:ss.fffffff"));

I know it's a pretty bad way to look at how long things take, but that's
how I got the .2+ second mark... Not sure why it's doing that in my main
program but not the sample one... in the sample one the time between
start and end doesn't change at all.

In your main program, is anything else happening at the same time? For
instance, is myQueue synchronized, and is something else is locking on
it?

Jon
 
Yep... that's exactly what was happening - I ended up finding a huge
flaw with the way I had originally designed the class. I designed it to
run in 3 threads (two of which needed that queue) when I could have done
everything in 2 threads and made the entire process around 15 times
faster, and an infinite amount of times safer! So that's what i'll be
doing this weekend... re-writing code from what i've learned ;)

~Benny
 
Back
Top