From 1ca61ba6999e754ff1cc0054ae7e77adbd9bbf99 Mon Sep 17 00:00:00 2001 From: "Eric J. Korpela" Date: Fri, 23 Jul 2004 04:04:21 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=3946 --- checkin_notes | 35 ++++++++++++++++++- html/inc/cache.inc | 43 +++++++++++++++++++++++- html/inc/profile.inc | 2 +- html/project.sample/cache_parameters.inc | 12 ++++++- html/user/download.php | 2 +- html/user/hosts_user.php | 4 +-- html/user/sample_index.php | 2 +- html/user/show_user.php | 2 +- html/user/team_display.php | 2 +- html/user/top_hosts.php | 2 +- html/user/top_teams.php | 2 +- html/user/top_users.php | 2 +- 12 files changed, 97 insertions(+), 13 deletions(-) diff --git a/checkin_notes b/checkin_notes index 2b3c6d9e44..9e48f86de1 100755 --- a/checkin_notes +++ b/checkin_notes @@ -15463,7 +15463,7 @@ Rom July 19 2004 - Tag for 4.01 release, all platforms boinc_release_4_01 -Eric +Eric K. July 20 2004 - Added cache control headers to the cached php pages to reduce CGI load on the web server. The headers include Last-Modified, Expires, and Cache-Control: public, max-age=. Expiration and max-age are @@ -15474,6 +15474,10 @@ Eric html/inc/cache.inc + + + + Rom July 19 2004 - Fix a bug where during the benchmarking process all the active tasks would die off. @@ -15631,3 +15635,32 @@ Jeff 22 July 2004 db/ boinc_db.C + +Eric K. July 22 2004 + - Worked a bit more on the caching... Improvements include.... + - A parameter file html/project.sample/cache_parameters.inc that + contains the cache TTL values for differing types of files, maximum + cache size and minimum free disk space in the cache directory. + - Reducing the cache TTL to 0 for a specific file type results in + caching being turned off for that file type. + - The cache now has 256 subdirectories to speed up file open times. + - The cache directories will be automatically built if they don't exist + when first called + - The cache size is checked every CACHE_SIZE_CHECK_FREQ page accesses. + If the max size or min free space are exceeded, file are purged in + order of age until the cache size is below the cutoff. + html/ + inc/ + cache.inc + profile.inc + project.sample/ + cache_parameters.inc + user/ + download.php + hosts_user.php + sample_index.php + show_user.php + team_display.php + top_hosts.php + top_teams.php + top_users.php diff --git a/html/inc/cache.inc b/html/inc/cache.inc index 53849b403d..307e1c8d67 100644 --- a/html/inc/cache.inc +++ b/html/inc/cache.inc @@ -27,9 +27,50 @@ function get_path($params) { return $path; } +function disk_usage($dir) { + $usage=0; + if ($handle=@opendir($dir)) { + while ($file=readdir($handle)) { + if (($file != ".") && ($file != "..")) { + if (@is_dir($dir."/".$file)) { + $usage+=disk_usage($dir."/".$file); + } else { + $usage+=@filesize($dir."/".$file); + } + } + } + @closedir($handle); + } + return $usage; +} + +function clean_cache($max_age,$dir="../cache") { + if ($handle=@opendir($dir)) { + while ($file=readdir($handle)) { + if (($file != ".") && ($file != "..")) { + if (@is_dir($dir."/".$file)) { + clean_cache($max_age,$dir."/".$file); + } else { + if ((time()-@filemtime($file))>$max_age) @unlink($file); + } + } + } + @closedir($handle); + } +} + function start_cache($max_age, $params=""){ + $path = get_path($params); + // check free disk space every once in a while + if (!(rand() % CACHE_SIZE_CHECK_FREQ)) { + $too_old=86400; + while ((disk_free_space("../cache") < MIN_FREE_SPACE) || + (disk_usage("../cache") > MAX_CACHE_USAGE)) { + clean_cache($too_old); + $too_old/=2; + } + } if ($max_age) { - $path = get_path($params); $request = getallheaders(); // Check to see if this is a conditional fetch. $lastmodified = @filemtime($path); diff --git a/html/inc/profile.inc b/html/inc/profile.inc index 5fde04cc7d..e73e11c51d 100644 --- a/html/inc/profile.inc +++ b/html/inc/profile.inc @@ -462,7 +462,7 @@ function show_profile($userid, $verify_mode=false) { if (!$verify_mode) { page_tail(); } - if ($caching) end_cache($cache_args); + if ($caching) end_cache(USER_PROFILE_TTL,$cache_args); } function show_profile_summary($user, $profile, $can_edit, $verify_mode) { diff --git a/html/project.sample/cache_parameters.inc b/html/project.sample/cache_parameters.inc index 54dfa60aa1..adcadefe56 100644 --- a/html/project.sample/cache_parameters.inc +++ b/html/project.sample/cache_parameters.inc @@ -1,11 +1,21 @@ diff --git a/html/user/download.php b/html/user/download.php index 4ecd6e3f71..4411d7bd85 100644 --- a/html/user/download.php +++ b/html/user/download.php @@ -52,5 +52,5 @@ require_once("../inc/download.inc"); "; page_tail(); -end_cache(); +end_cache(DOWNLOAD_PAGE_TTL); ?> diff --git a/html/user/hosts_user.php b/html/user/hosts_user.php index db51d3a99a..6dbdfa4e6c 100644 --- a/html/user/hosts_user.php +++ b/html/user/hosts_user.php @@ -21,7 +21,7 @@ user_host_table_start(false); } else { echo "Hidden\n"; - end_cache($cache_args); + end_cache(USER_PAGE_TTL,$cache_args); exit(); } $private = false; @@ -42,5 +42,5 @@ mysql_free_result($result); echo "\n"; page_tail(); - if ($caching) end_cache($cache_args); + if ($caching) end_cache(USER_PAGE_TTL,$cache_args); ?> diff --git a/html/user/sample_index.php b/html/user/sample_index.php index 710b6f7a6e..7eba0aa83d 100644 --- a/html/user/sample_index.php +++ b/html/user/sample_index.php @@ -111,5 +111,5 @@ echo "-->\n"; page_tail(true); -//end_cache(); +//end_cache(INDEX_PAGE_TTL); ?> diff --git a/html/user/show_user.php b/html/user/show_user.php index e97d2d81d9..1108f1854a 100644 --- a/html/user/show_user.php +++ b/html/user/show_user.php @@ -38,5 +38,5 @@ page_tail(); } } - end_cache($cache_args); + end_cache(USER_PAGE_TTL,$cache_args); ?> diff --git a/html/user/team_display.php b/html/user/team_display.php index beeebcb584..bcfa4e65b3 100644 --- a/html/user/team_display.php +++ b/html/user/team_display.php @@ -35,6 +35,6 @@ if (!$team) { display_team_page($team, $offset, $sort_by); -end_cache($cache_args); +end_cache(TEAM_PAGE_TTL,$cache_args); ?> diff --git a/html/user/top_hosts.php b/html/user/top_hosts.php index 0e438818ac..7c207d23df 100644 --- a/html/user/top_hosts.php +++ b/html/user/top_hosts.php @@ -50,6 +50,6 @@ page_tail(); if ($offset < 1000) { - end_cache($cache_args); + end_cache(TOP_PAGES_TTL,$cache_args); } ?> diff --git a/html/user/top_teams.php b/html/user/top_teams.php index d5380c4f4a..1223e70e6d 100644 --- a/html/user/top_teams.php +++ b/html/user/top_teams.php @@ -55,7 +55,7 @@ page_tail(); if ($offset < 1000) { - end_cache($cache_args); + end_cache(TOP_PAGES_TTL,$cache_args); } } ?> diff --git a/html/user/top_users.php b/html/user/top_users.php index 91351448ce..33898c3649 100644 --- a/html/user/top_users.php +++ b/html/user/top_users.php @@ -51,6 +51,6 @@ page_tail(); if ($offset < 1000) { - end_cache($cache_args); + end_cache(TOP_PAGES_TTL,$cache_args); } } ?>