5 Replies Latest reply: Jun 17, 2010 2:22 PM by sneakyimp RSS

    15 second time out - "batchifying" my lengthy task not helping

    sneakyimp Community Member

      I have a highly intensive benchmark/testing chore and I'm getting the 15-second timeout error despite my best efforts to keep my script running.

       

      Basically I'm making about 1.2 million remote procedure calls (RPCs) over a socket and want to check the results of these rpcs.

       

      I can make the calls just fine.  The problem I'm having is verifying the results of all these calls once the loop is complete.

       

      Once the calls have all been sent, my flash movie moves to frame 7 which initializes a bunch of variables that I need for my RPC checking loop.

       

      Frame 8 does all the work.  The first thing it does is stop the playhead for my main movie. Then it sets up a timer to wait for minute or two until any straggling RPC responses come in.  [It's been my experience that these are likely to straggle in for several minutes when I'm really pushing the server hard.]

       

      If the timer gets too high, the [b]checkResponse[/b] function returns and the playhead moves to frame 9 which checks to see if I've checked all the RPCs.  If not, the playhead returns to from 8 which skips the timer this time and starts checking immediately.

       

      The output I'm getting ends up like this:

       

      elapsed time:4985
      elapsed time:4985
      Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
          at flash_fla::MainTimeline/checkResponses()
          at flash_fla::MainTimeline/frame8()
          at flash.display::MovieClip/gotoAndPlay()
          at flash_fla::MainTimeline/runDelayedResponseCheck()
          at flash.utils::Timer/_timerDispatch()
          at flash.utils::Timer/tick()

       

      As you can see, my timer only reaches about 5 seconds before the timeout exception occurs.  I've been searching for something in AS3 to return the current script execution time, but am not having much luck.

       

      Here's an abbreviated bit of code from frame 8

       

       

      trace('entered Frame 8');
      this.stop();

      // if the checks have already started, skip the postSendDelay
      if (checksStarted) {
          // if we've already started the check, continue immediately
          checkResponses();
          this.gotoAndPlay(9);
      } else {
          // otherwise, set up a timer to wait for the RPCs to finish rolling in
          var checkTimer:Timer = new Timer(postSendDelay, 1);
          checkTimer.addEventListener(TimerEvent.TIMER, runDelayedResponseCheck);
          checkTimer.start();
      }



      function runDelayedResponseCheck(evt:Event):void {
          checkResponses();
          this.gotoAndPlay(9);
      }


      function checkResponses():Boolean {
          checksStarted = true;


          var startDate:Date = new Date();
        
          for (var thd=startThd; thd <= threads_count; thd++) {
              for (var itr=startItr; itr <= iteration_count; itr++) {


                  // check our execution time in case we running long
                  var now:Date = new Date();
                  var elapsedTime:Number = now.valueOf() - startDate.valueOf();
                  trace('elapsed time:' + elapsedTime);
                  if ( elapsedTime > timeOut) {
                      trace('time limit reached, going to next frame');
                      startThd = thd;
                      startItr = itr;


                      return false; // return and move on to next frame
                  }
                
                  // check the current RPC
                  // LENGTHY CHECK BLAH BLAH BLAH


              } // foreach iteration
              startItr = 1;
          } // foreach thread


          checksComplete = true;
          trace('checkResponse ran to completion');
          return true;


      } // checkResponses()


        • 1. Re: 15 second time out - "batchifying" my lengthy task not helping
          kglad CommunityMVP

          you can't do any timer checking in a for-loop (or nested for-loop).  well, you can check but the timer won't advance during a for-loop.

           

          so, set your timeout for greater than 15 seconds or break your for-loops up into several for-loops with an enterframe tick between the end of one and the start of the next..

          • 2. Re: 15 second time out - "batchifying" my lengthy task not helping
            sneakyimp Community Member

            Thanks kglad.  I always appreciate your help.

             

            Not sure what you mean about the timer not advancing in a for loop.  This bit of code does in fact show the elapsedTime value increasing from 0 to about 4985 milliseconds:

             
                           var now:Date = new Date();
                           var elapsedTime:Number = now.valueOf() - startDate.valueOf();
                           trace('elapsed time:' + elapsedTime);
                           if ( elapsedTime > timeOut) {
                                trace('time limit reached, going to next frame');
                                startThd = thd;
                                startItr = itr;

                                return false; // return and move on to next frame
                           }

             

            I'm also puzzled about how to increase my timeout.  I've read that it's in the publish options for a movie but cannot seem to locate where.

             

            I think the correct solution here is to break up my for loops as you have suggested.

            • 3. Re: 15 second time out - "batchifying" my lengthy task not helping
              sneakyimp Community Member

              AHA.  Just found timeout.  It's the last input on the publish settings. Silly me.

              • 4. Re: 15 second time out - "batchifying" my lengthy task not helping
                sneakyimp Community Member

                I broke up my code across several frames and it was working -- up to a point.  I got a stack overflow problem (despite not using any recursive functions).

                 


                 

                Interestingly, I managed to eliminate the stack overflow problem by  moving all my variable declarations outside of the loop.  The timeout  problem was still happening though.  I think the issue is because my  testing had generated a huge backlog of incoming socket data which was  really slowing things down -- so much, in fact, that a single iteration  of the loop was taking more than 15 seconds.

                • 5. Re: 15 second time out - "batchifying" my lengthy task not helping
                  kglad CommunityMVP

                  increase the timeout length.