[Rt-devel] [PATCH] Callback stat cache
Matt Mankins
matt at mankins.net
Fri Sep 17 15:44:42 EDT 2004
In doing some profiling someone noticed a bunch of stats looking for
Callback modifications. In the "every little bit counts" category, this
patch caches the stat/response so that subsequent requests can use the
in-memory response rather than go out and get the fresh value via a system
call.
If I understand it correctly, on production systems, it should be a rare
event that new Callbacks are added. If they are added, the sysadmin could
certainly restart RT to make them show up.
I added this to my RT_Siteconfig:
# Callback Timeout
# Seconds until the callback cache times out Set this high (86400) for
# production systems, low for development (0) [default]
Set($CallbackTimeout, 10000);
.
.
.
And it seems to have made some difference, although I haven't run any
tests to verify.
This obviously only makes sense in persistent environments.
Let me know if you see any booboos/comments/etc.
Matt Mankins
http://www.loremipsumbooks.com/
-------------- next part --------------
*** html/Elements/Callback Sun Mar 28 04:04:08 2004
--- /tmp/Callback Fri Sep 17 19:12:53 2004
***************
*** 25,37 ****
my (%cache, $check);
</%once>
<%init>
! # checks for inode change time for each callback directory
! my $new_check = join(
! $;, map { $_->[1] => (stat("$_->[1]/Callbacks"))[10] } $m->interp->resolver->comp_root_array
! ) or return;
$Page = $m->callers(1)->path unless ($Page);
my $callbacks;
if ($new_check eq $check) {
$callbacks = $cache{$Page,$_CallbackName};
--- 25,56 ----
my (%cache, $check);
</%once>
<%init>
! my $callback_timeout = $RT::CallbackTimeout || 0; # seconds.
!
! my $new_check;
! my $start_time = time;
$Page = $m->callers(1)->path unless ($Page);
+ if ( ( $start_time - ($RT::Callback::cache{$Page.$_CallbackName."time"}) ) > $callback_timeout)
+ {
+ # Stat Cache miss, do the stat
+
+ # checks for inode change time for each callback directory
+ $new_check = join(
+ $;, map { $_->[1] => (stat("$_->[1]/Callbacks"))[10] } $m->interp->resolver->comp_root_array
+ ) or return;
+
+ # set the stat cache
+ $RT::Callback::cache{$Page.$_CallbackName."time"} = $start_time;
+ $RT::Callback::cache{$Page.$_CallbackName} = $new_check;
+ }
+ else
+ {
+ # we'll use our stat cache instead of stat'ing
+ $new_check = $RT::Callback::cache{$Page.$_CallbackName};
+ }
+
my $callbacks;
if ($new_check eq $check) {
$callbacks = $cache{$Page,$_CallbackName};
***************
*** 49,56 ****
my $invalid_base = "/Callbacks/$Page/$_CallbackName";
@$callbacks = grep !/^$invalid_base$/, @$callbacks;
-
-
$cache{$Page,$_CallbackName} = $callbacks;
}
--- 68,73 ----
More information about the Rt-devel
mailing list