Roxen.git / server / base_server / roxen.pike

version» Context lines:

Roxen.git/server/base_server/roxen.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2009, Roxen IS.   //   // The Roxen WebServer main program.   //   // Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.   // ABS and suicide systems contributed freely by Francesco Chemolli    - constant cvs_version="$Id: roxen.pike,v 1.1084 2011/08/15 14:13:48 grubba Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.1085 2011/08/22 20:45:39 mast Exp $";      //! @appears roxen   //!   //! The Roxen WebServer main program.      // The argument cache. Used by the image cache.   ArgCache argcache;      // Some headerfiles   #define IN_ROXEN
Roxen.git/server/base_server/roxen.pike:677: Inside #if undefined(NO_SLOW_REQ_BT)
   if (this_thread() != backend_thread) error ("Run from wrong thread.\n");   #endif    if (Pike.Backend monitor = slow_be_call_out && slow_req_monitor) {    monitor->remove_call_out (slow_be_call_out);    slow_be_call_out = 0;    }   }      protected void slow_be_after_cb()   { +  // FIXME: This should try to compensate for delays due to the pike +  // gc, because it just causes noise here.   #ifdef DEBUG    if (this_thread() != backend_thread) error ("Run from wrong thread.\n");   #endif    if (slow_be_timeout > 0.0)    if (Pike.Backend monitor = slow_req_monitor)    slow_be_call_out = monitor->call_out (dump_slow_req, slow_be_timeout,    this_thread(), slow_be_timeout);   }      void slow_req_count_changed()
Roxen.git/server/base_server/roxen.pike:1209:    // I hope that this will solve all your problems. /per    if( really > 0 )    return lambda( mixed ... args ){ call_out( f, 0, @args ); };    if( really < 0 )    return f;    return SignalAsyncVerifier( f )->call;   }      #ifdef THREADS   protected Thread.Queue bg_queue = Thread.Queue(); - protected int bg_process_running; + protected Thread.Thread bg_process_thread;      // Use a time buffer to strike a balance if the server is busy and   // always have at least one busy thread: The maximum waiting time in   // that case is somewhere between bg_time_buffer_min and   // bg_time_buffer_max. If there are only short periods of time between   // the queue runs, the max waiting time will shrink towards the   // minimum.   protected constant bg_time_buffer_max = 30;   protected constant bg_time_buffer_min = 0;   protected int bg_last_busy = 0;
Roxen.git/server/base_server/roxen.pike:1238: Inside #if defined(THREADS)
  int bg_acc_time = 0;   int bg_acc_cpu_time = 0;      int bg_queue_length()   {    return bg_queue->size();   }      protected void bg_process_queue()   { -  if (bg_process_running) return; +  if (bg_process_thread) return;    // Relying on the interpreter lock here. -  bg_process_running = 1; +  bg_process_thread = this_thread();       int maxbeats =    min (time() - bg_last_busy, bg_time_buffer_max) * (int) (1 / 0.01);      #ifndef NO_SLOW_REQ_BT    Pike.Backend monitor;    mixed call_out;   #endif       if (mixed err = catch {
Roxen.git/server/base_server/roxen.pike:1348: Inside #if defined(THREADS) and #if defined(DEBUG_BACKGROUND_RUN)
   "took %g ms cpu time and %g ms real time\n",    task_vtime * 1000, task_rtime * 1000);   #endif       if (busy_threads > 1) bg_last_busy = time();    }    }) {   #ifndef NO_SLOW_REQ_BT    if (call_out) monitor->remove_call_out (call_out);   #endif -  bg_process_running = 0; +  bg_process_thread = 0;    handle (bg_process_queue);    throw (err);    } -  bg_process_running = 0; +  bg_process_thread = 0;    if (bg_queue->size()) {    handle (bg_process_queue);    // Sleep a short while to encourage a thread switch. This is a    // kludge to avoid starving non-handler threads, since pike    // currently (7.8.503) doesn't switch threads reliably on yields.    sleep (0.001);    }   }   #endif    -  + Thread.Thread background_run_thread() + //! Returns the thread currently executing the background_run queue, + //! or 0 if it isn't being processed. + { + #ifdef THREADS +  return bg_process_thread; + #else +  // FIXME: This is not correct. Should return something nonzero when +  // called from the call out. But noone is running without threads +  // nowadays anyway. +  return 0; + #endif + } +    mixed background_run (int|float delay, function func, mixed... args)   //! Enqueue a task to run in the background in a way that makes as   //! little impact as possible on the incoming requests. No matter how   //! many tasks are queued to run in the background, only one is run at   //! a time. The tasks won't be starved regardless of server load,   //! though.   //!   //! The function @[func] will be enqueued after approximately @[delay]   //! seconds, to be called with the rest of the arguments as its   //! arguments.
Roxen.git/server/base_server/roxen.pike:1419: Inside #if defined(THREADS)
   return 0;       class enqueue(function func, mixed ... args)    {    int __hash() { return hash_value(func); }    int `==(mixed gunc) { return func == gunc; }    string _sprintf() { return sprintf("background_run(%O)", func); }    mixed `()()    {    bg_queue->write (({func, args})); -  if (!bg_process_running) +  if (!bg_process_thread)    handle (bg_process_queue);    }    };       if (delay)    return call_out (enqueue(func, @args), delay);    else {    enqueue(func, @args)();    return 0;    }