Queue.Dequeue () slow?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Benny Raymond

    Queue.Dequeue () slow?

    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.Dequ eue();

    is there a faster way?
  • Jon Skeet [C# MVP]

    #2
    Re: Queue.Dequeue () slow?

    Benny Raymond <benny@pocketro cks.com> wrote:[color=blue]
    > 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.Dequ eue();
    >
    > is there a faster way?[/color]

    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.

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    • Benny Raymond

      #3
      Re: Queue.Dequeue () slow?

      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.To String("mm:ss.f ffffff"));
      ServerMessage m = (ServerMessage) myQueue.Dequeue ();
      Debug.WriteLine ("END DQ: " + DateTime.Now.To String("mm:ss.f ffffff"));

      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.

      Jon Skeet [C# MVP] wrote:[color=blue]
      > Benny Raymond <benny@pocketro cks.com> wrote:
      >[color=green]
      >>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.Dequ eue();
      >>
      >>is there a faster way?[/color]
      >
      >
      > 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.
      >[/color]

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Queue.Dequeue () slow?

        Benny Raymond wrote:[color=blue]
        > 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.To String("mm:ss.f ffffff"));
        > ServerMessage m = (ServerMessage) myQueue.Dequeue ();
        > Debug.WriteLine ("END DQ: " + DateTime.Now.To String("mm:ss.f ffffff"));
        >
        > 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.[/color]

        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

        Comment

        • Benny Raymond

          #5
          Re: Queue.Dequeue () slow?

          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

          Jon Skeet [C# MVP] wrote:[color=blue]
          > Benny Raymond wrote:
          >[color=green]
          >>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.WriteLi ne("START DQ: " + DateTime.Now.To String("mm:ss.f ffffff"));
          >>ServerMessa ge m = (ServerMessage) myQueue.Dequeue ();
          >>Debug.WriteLi ne("END DQ: " + DateTime.Now.To String("mm:ss.f ffffff"));
          >>
          >>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.[/color]
          >
          >
          > 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
          >[/color]

          Comment

          Working...