Branch: Tag:

2001-02-27

2001-02-27 02:54:34 by Per Hedbor <ph@opera.com>

Added minimum bandwidth support, and added TIMER_*() macros for performance optimization reasons.

Rev: server/base_server/configuration.pike:1.418
Rev: server/base_server/global_variables.pike:1.63
Rev: server/base_server/roxen.pike:1.637
Rev: server/protocols/http.pike:1.306
Rev: server/protocols/prot_http.pike:2.2

1:   // A vitual server's main configuration   // Copyright © 1996 - 2000, Roxen IS. - constant cvs_version = "$Id: configuration.pike,v 1.417 2001/02/23 03:58:24 mast Exp $"; + constant cvs_version = "$Id: configuration.pike,v 1.418 2001/02/27 02:54:18 per Exp $";   #include <module.h>   #include <module_constants.h>   #include <roxen.h>   #include <request_trace.h> -  + #include <timers.h>    -  +    #define CATCH(P,X) do{mixed e;if(e=catch{X;})report_error("While "+P+"\n"+describe_backtrace(e));}while(0)      // --- Locale defines ---
182:   // A list of priority objects   array (Priority) pri = allocate_pris();    - public mapping modules = ([]); + mapping modules = ([]);   //! All enabled modules in this site.   //! The format is "module":{ "copies":([ num:instance, ... ]) }    - public mapping (RoxenModule:string) otomod = ([]); + mapping (RoxenModule:string) otomod = ([]);   //! A mapping from the module objects to module names      
615:    log_format[(int)(b/":")[0]] = fix_logging((b/":")[1..]*":");   }    - public void log(mapping file, RequestID request_id) + void log(mapping file, RequestID request_id)   {    function f;   
639:    roxen.run_log_format( form, log_function, request_id, file );   }    - public array(string) userinfo(string u, RequestID|void id) + array(string) userinfo(string u, RequestID|void id)   //! @note DEPRECATED COMPATIBILITY FUNCTION   //!   //! Fetches user information from the authentication module by calling
651:    return uid->compat_userinfo();   }    - public array(string) userlist(RequestID|void id) + array(string) userlist(RequestID|void id)   //! @note DEPRECATED COMPATIBILITY FUNCTION   //!   //! Fetches the full list of valid usernames from the authentication
664:    return list;   }    - public array(string) user_from_uid(int u, RequestID|void id) + array(string) user_from_uid(int u, RequestID|void id)   //! @note DEPRECATED COMPATIBILITY FUNCTION   //!   //! Return the user data for id u from the authentication module. The
780:   }       - public string last_modified_by(Stdio.File file, RequestID id) + string last_modified_by(Stdio.File file, RequestID id)   {    Stat s;    int uid;
1049: Inside #if defined(THREADS)
  {    Thread.MutexKey key;    function|int l; -  +  TIMER_START(module_lock);    if (functionp(f)) {    f = function_object(f);    }
1081: Inside #if defined(THREADS)
   locked[f]++;    key = l();    } +  TIMER_END(module_lock);    return key;   }   
1183:       if(!no_magic)    { +  TIMER_START(internal_magic);   #ifndef NO_INTERNAL_HACK    // Find internal-foo-bar images    // min length == 17 (/internal-roxen-?..)
1200:    case "roxen":    TRACE_LEAVE("Magic internal roxen image");    if(loc=="unit" || loc=="pixel-of-destiny") -  return (["data":"GIF89a\1\0\1\0\200ÿ\0ÀÀÀ\0\0\0!ù\4\1\0\0\0\0,\0\0\0\0\1\0\1\0\0\1\1""2\0;", +  { +  TIMER_END(internal_magic); +  return (["data":"GIF89a\1\0\1\0\200ÿ\0ÀÀÀ\0\0\0!ù\4\1\0\0\0\0," +  "\0\0\0\0\1\0\1\0\0\1\1""2\0;",    "type":"image/gif" ]); -  +  }    if(has_prefix(loc, "pixel-")) -  return (["data":sprintf("GIF89a\1\0\1\0\200\0\0\0\0\0%c%c%c,\0\0\0\0\1\0\1\0\0\2\2L\1\0;", +  { +  TIMER_END(internal_magic); +  return (["data":sprintf("GIF89a\1\0\1\0\200\0\0\0\0\0%c%c%c,\0\0\0" +  "\0\1\0\1\0\0\2\2L\1\0;",    @parse_color(loc[6..])),    "type":"image/gif" ]); -  +  } +  TIMER_END(internal_magic);    return internal_roxen_image(loc, id);       case "gopher":    TRACE_LEAVE("Magic internal gopher image"); -  +  TIMER_END(internal_magic);    return internal_gopher_image(loc);    }    }
1236: Inside #if defined(MODULE_LEVEL_SECURITY)
   } else {    TRACE_LEAVE("");    TRACE_LEAVE("Request denied."); +  TIMER_END(internal_magic);    return tmp2;    }   #endif
1252:    {    TRACE_LEAVE("");    TRACE_LEAVE(examine_return_mapping(fid)); +  TIMER_END(internal_magic);    return fid;    }    else
1285:    } else    TRACE_LEAVE("");    } +  TIMER_END(internal_magic);    }       // Well, this just _might_ be somewhat over-optimized, since it is
1293: Inside #if defined(URL_MODULES)
   {   #ifdef URL_MODULES    // Map URL-modules +  TIMER_START(url_modules);    foreach(url_module_cache||url_modules(), funp)    {    LOCK(funp);
1304: Inside #if defined(URL_MODULES)
   {    TRACE_LEAVE("");    TRACE_LEAVE("Returning data"); +  TIMER_END(url_modules);    return tmp;    }    if(objectp( tmp ))
1325: Inside #if defined(URL_MODULES)
   if(err) throw(err);    TRACE_LEAVE("");    TRACE_LEAVE("Returning data"); +  TIMER_END(url_modules);    return tmp;    }    TRACE_LEAVE(""); -  +  TIMER_END(url_modules);    }   #endif    -  +  TIMER_START(location_modules);    foreach(location_module_cache||location_modules(), tmp)    {    loc = tmp[0];
1346: Inside #if defined(MODULE_LEVEL_SECURITY)
   } else {    TRACE_LEAVE("");    TRACE_LEAVE("Request denied."); +  TIMER_END(location_modules);    return tmp2;    }   #endif
1362:    {    TRACE_LEAVE("");    TRACE_LEAVE(examine_return_mapping(fid)); +  TIMER_END(location_modules);    return fid;    }    else
1405:    (id->query?("?"+id->query):"");    new_query=Roxen.add_pre_state(new_query, id->prestate);    +  TIMER_END(location_modules);    return Roxen.http_redirect(new_query, id);    }    } -  +  TIMER_END(location_modules);    }       if(fid == -1)
1417:    TRACE_LEAVE("No magic requested. Returning -1.");    return -1;    } +  TIMER_START(directory_module);    if(dir_module)    {    LOCK(dir_module);
1429:    TRACE_LEAVE("No directory module. Returning 'no such file'");    return 0;    } +  TIMER_END(directory_module);    if(mappingp(fid))    {    TRACE_LEAVE("Returning data");
1437:    }       // Map the file extensions, but only if there is a file... +  TIMER_START(extension_module);    if(objectp(fid) &&    (tmp = file_extension_modules(loc = Roxen.extension(id->not_query, id))))    {
1454: Inside #if defined(MODULE_LEVEL_SECURITY)
   {    TRACE_LEAVE("");    TRACE_LEAVE("Permission denied"); +  TIMER_END(extension_module);    return tmp;    }   #endif
1466:    {    TRACE_LEAVE("");    TRACE_LEAVE("Returning data"); +  TIMER_END(extension_module);    return tmp;    }    if(fid && tmp != fid)
1477:    TRACE_LEAVE("");    }    } +  TIMER_END(extension_module);       if(objectp(fid))    { -  +  TIMER_START(content_type_module);    if(stringp(id->extension)) {    id->not_query += id->extension;    loc = Roxen.extension(id->not_query, id);
1491:    if(tmp)    {    TRACE_LEAVE(""); +  TIMER_END(content_type_module);    return ([ "file":fid, "type":tmp[0], "encoding":tmp[1] ]);    }    TRACE_LEAVE(""); -  +  TIMER_END(content_type_module);    return ([ "file":fid, ]);    } -  +     if(!fid)    TRACE_LEAVE("Returned 'no such file'.");    else
1508:    function funp;    mixed file;    REQUEST_WERR("handle_request()"); +  TIMER_START(handle_request); +  TIMER_START(first_modules);    foreach(first_module_cache||first_modules(), funp)    {    if(file = funp( id ))
1517:    return id->conf->handle_request(id);    }    } +  TIMER_END(first_modules);    if(!mappingp(file) && !mappingp(file = get_file(id)))    {    mixed ret; -  +  TIMER_START(last_modules);    foreach(last_module_cache||last_modules(), funp) if(ret = funp(id)) break;    if (ret == 1) {    REQUEST_WERR("handle_request(): Recurse"); -  +  TIMER_END(last_modules); +  TIMER_END(handle_request);    return handle_request(id);    }    file = ret; -  +  TIMER_END(last_modules);    } -  +  TIMER_END(handle_request);    REQUEST_WERR("handle_request(): Done"); -  +  MERGE_TIMERS(roxen);    return file;   }   
1536:   //! modules, including the filter modules. This function is mostly a   //! wrapper for <ref>low_get_file()</ref>.   { +  TIMER_START(get_file);    int orig_internal_get = id->misc->internal_get;    id->misc->internal_get = internal_get;   
1543:    mapping res2;    function tmp;    res = low_get_file(id, no_magic); +  TIMER_END(get_file);       // finally map all filter type modules.    // Filter modules are like TYPE_LAST modules, but they get called    // for _all_ files. -  +  TIMER_START(filter_modules);    foreach(filter_module_cache||filter_modules(), tmp)    {    TRACE_ENTER("Filter module", tmp);
1559:    } else    TRACE_LEAVE("");    } +  TIMER_END(filter_modules);       id->misc->internal_get = orig_internal_get;    return res;