Article View: news.software.nntp
Article #2827New version of actgroups: Automatic tuning the expire.ctl
From: Yufan Hu
Date: Thu, 18 Aug 1994 11:54
Date: Thu, 18 Aug 1994 11:54
465 lines
15469 bytes
15469 bytes
Hi,
Here is an updated version of my perl script which automatically tunes the
expire.ctl file to make effect use of spool disk space. The readme part
follows. The script is attached to the end of this message. See the
beginning of the script for a list of options and configuration bits.
See the end of the script for a list of changes made since my last posting.
Comments and bug reports are welcome.
Yufan.
==========
actgroups -- Automating news group expiring policy.
1. The problem.
I am a news administrator. We cannot afford a big disk to carry all
the news groups for long time.
Yet I want to carry all the news groups. I know my users will not
access to all the groups. But I do not know which groups are
really needed by the users.
I want:
the users be able to freely access any groups they want,
the groups being accessed by the user being kept a bit longer
so they are available to the users.
I do NOT want:
to keep all the groups long because I cannot afford the
necessary disk space,
to check the news.notices file to see which groups are accessed
and change expire.ctl everyday, manually.
to let the users explicitly request for some groups to be kept
longer (neither the users nor me are happy with this).
2. My solution:
There does not seem to be a good policy for expiring news groups. The
only solution to me is to check the news.notices file to see which
groups are accessed daily and change the expire.ctl accordingly. Thus
I can have a fine-grain control over the expiring of the groups. But
of course I do not like to do it myself. So I wrote a program called
"actgroups" which will automatically do the above job for me, daily.
3. Expiring policy:
The "actgroups" will check the news.notice file everyday to see which
groups are accessed for that day. By defining a default expiring time,
say 10 days, then if a group is detected being accessed within this
10 days, we consider this groups as currently active (being accessed).
The policy:
a) If a group is accessed within the last 10 days (or any configured
number of days), that group will be kept for another 10 days.
b) If a group is not accessed within the the last 10 days, the group
will be kept for 1 day to enable interested users to explore it
in the future.
4. Implementation:
"actgroups" is implemented in Perl. It uses a DBM database to stored
the time a group was last detected in the news.notices file. When
it is run, "actgroups" will first scan the news.notices file to find
any groups which are accessed, then stores the group name and current
time pair in the database. Then it scans the database, and compares the
time of each group in the database with the current time. If the
difference is smaller than 10 days, it will write a line looks like:
groupname:A:1:10:14
into the expire.ctl file.
5. The expire.ctl file:
Normally you need only a line like:
*:A:1:1:1
in your expire.ctl file, which says that everything should stay only
for one day if not otherwise stated. The "actgroups" will produce
fine-grained expire entry for each active group it detects.
You still retain the original way to control the expire.ctl file. If
you put something like:
alt.binaries.pictures.*:A:1:3:5
then "actgroups" will ignore all groups in the alt.binaries.pictures
subtree and the above line remains exactly the same meaning as without
"actgroups".
When "actgroups" changes the expire.ctl file, it will backup the
original one with a file name ended with the week day.
6. The initialisation of the database:
The proper operation of the "actgroups" relies on the database which
contains the group names and their last detected access time. When
first run it, the database is empty. "actgroups" has to look in the
news.notices file to collect the groups being accessed. It is not
convincing that the groups collected in the first day will represent
the correct set of groups being accessed. Thus "actgroups" will
allow for 7 days to establish the database.
WARNING: you should not change the "*:A:..." line in your expire.ctl
to "*:A:1:1:1" in this case. Otherwise everything will be expired
tomorrow!
If you are eager to see the result. There is a work around. Suppose
all the news.notices files for the past week are still kept in OLD
directory, in compressed form (it is the case for me), then you can
uncompress them, cat them together, and run actgroups with '-l' option
actgroups -l logfile
and change the value of $wait from 7 to 1, then it will take
effect the following day.
See the beginning of the script for a list of options and configuration.
7. Evaluation:
Before installing actgroups:
I had 3500 groups, 700 MB disk space. Default expiring time was
3 days, for comp.* 7 days, and I had the disk space problem
which frequently makes the innd into the "throttle" state.
After installing actgroups:
I have 4300 groups, a 800 groups in increase, the default
expiring time for accessed groups is 10 days, for everything
else, 1 day. The whole system consumes about 500 MB, with
about 400 "active" groups.
Conclusion: with actgroups I can run the news server with 800 more
groups and 200 MB less disk space without reducing the service.
8. Credit/Disclaim
"actgroups" is created by Yufan Hu (Y.Hu@ulst.ac.uk) in the Interactive
Systems Centre of University of Ulster, Norther Ireland.
The author appreicate an e-mail acknowledge if you are using
actgroups, just wish to know who is using it. Thanks.
You are free to use this piece of software. Suggestions, praises and
criticise are all welcome.
Finally, I have to say that I hope this software will be of use to
everybody but I disclaim any responsiblity resulted from using the
software. Run it at your own risk.
========================Cut Here=====================================
#!/usr/local/bin/perl
# Active Groups -- Detecting actively accessed news groups and setting
# expire.ctl accordingly
$progname = "actgroups";
$version = "Ver 0.03b, 18 August 1994";
$author = "Yufan Hu <Y.Hu@ulst.ac.uk>";
require 'getopts.pl';
# Usage: run actgroups everyday before expire starts. You can put it
# in the crontab to start it before news.daily. It is essential to
# run actgroups before the news.notices file is moved to OLD and
# gets compressed.
# Or:
# actgroups -l logfile
# for initialising the active group database
# The log file and expire.ctl file are assumed to be of INN 1.4
# Other options are:
# -d turn on debugging
# -m mail results to news user
# -h do not keep a "hosts" log
#
# Copyright: Copyrighted by Yufan Hu <Y.Hu@ulst.ac.uk>, 1994
#
# Disclaim: Use it at your own risk.
#
############# Configuration starts here ########################
# The following should be changed according to your system setting up
# $LastRead: the path name of the database to store the
# last access time of group
# $newslog: the log file of innd & nnrpd (news.notice)
# $expire: the expire.ctl file path name
# $hostslog: log of hosts with their last accessing time
###############################################################
$LastRead = "/usr/local/news/LastRead.log";
$newslog = "/var/log/news/news.notice";
$expire = "/usr/local/news/expire.ctl";
$hostslog = "/usr/local/news/Hosts.log";
# $default is the number of days for articles to be kept if the coresponding
# group is accessed (see expire.ctl for the meaning)
# NB. The patterns specified manually at the beginning of the expire.ctl
# take precidence
# Keep 14 days for accessed groups
$default = 10;
$purge = 14;
# Binary groups usually eat up more disk space. This is a separate
# control for groups whose names contain the word "binaries"
# keep 7 days for binary groups
$bindefault = 7;
# All the rest remain for this amount of time only
$keeprest = 1;
# The accessed group database has to be established before proper expiring
# list being set up. $wait can be set to the number of days for collecting
# accessed groups from the log file and establish the database
#
# You can cat together all the news.notices files stored in the OLD directory
# and run actgroups once with '-l' option to collect the accessed groups
# then set $wait to 1 to start automatical tunning the next day
# wait for 7 days before starting updating expire.ctl
$wait = 7;
# Flag to do host log info
$do_hosts = 1;
################# Debug Only #################################
$debug = 0;
#################################################################
# Anything below should not need to be changed
do Getopts('l:dhm');
$newslog = $opt_l if ($opt_l);
$debug = 1 if ($opt_d);
$do_hosts = 0 if ($opt_h);
if($debug){
$warn .= "Logfile: $newslog\n";
}
$mail = "Mail -s Active-Groups news";
$expire_new = "$expire.new";
# Seconds in a day
$day = 3600 * 24;
$keeptime = $default * $day;
$wait = $wait * $day;
# open the database recording the time the group was last read
# access this database as an associated array
dbmopen(LASTREAD, $LastRead, 0600);
# open the news log file -- usually the news.notice
open(LOG, $newslog);
# get the current time
$now = time;
if($do_hosts) {
# Initialising the hostslog array
%hostslog = ();
open(HOSTSLOG, $hostslog);
while(<HOSTSLOG>){
if(/^([^ ]+):\s+(.*)$/){
$hostslog{$1} = $2;
}
}
close(HOSTSLOG);
}
# scan through the log file, detecting any accessed groups within current day
# and store the current time in the database
while(<LOG>) {
if(/^(.*\d\d:\d\d:\d\d).*nnrpd.*:\s+(.*)\s+group ([^\s]+)\s\d+/){
$group = $3;
if( $debug && (! $LASTREAD{$group}) ){
$warn .= "Adding: $group\n";
}
$LASTREAD{$group} = $now;
$hostslog{$2} = "$1 $group";
}
}
close(LOG);
open(EXP, $expire);
open(EXP_NEW, ">$expire_new");
$start = "### Actively Accessed Groups Start ###";
$end = "### Actively Accessed Groups End ###";
# skip over everything in the begining of the expire.ctl file
@defined = ();
while(<EXP>){
if(!/$start/){
if(/^(.+):(.):(\d+|never):(\d+|never):(\d+|never)/){
$group = $1;
if($group eq '*'){
if($3 != 1 || $4 != $keeprest || $5 != $keeprest){
print EXP_NEW "##$_";
print EXP_NEW "*:$2:1:$keeprest:$keeprest\n";
next;
}
} else {
if($group =~ /[\*\+\?]/){
$group =~ s/([\*\+\?])/.$1/g;
}
push(@defined, $group);
}
}
print EXP_NEW $_;
} else { last; }
}
close(EXP);
# the automatic expire configuration starts here
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now);
$date = qx/date/;
chop($date);
$day = $wday;
if($date =~ /^([A-Z][a-z]+)\s/){
$day = $1;
}
$start_token = "### ACTGROUP START TIME ###";
if( ! $LASTREAD{$start_token} ) {
$LASTREAD{$start_token} = $now;
}
$start_time = $LASTREAD{$start_token};
require "ctime.pl";
chop($start_time_string = &ctime($start_time));
print EXP_NEW "$start
#############################################################
## Automatically generated by $progname ($version)
## Auther: $author
## Date: $date
## Started from:$start_time_string
##
## Do NOT change anything below this line. They are automatically
## generated by $progname
##
#############################################################
";
$total = 0;
# Scan over the database. If a group was accessed within the predefined
# keeptime, then change the expire time for that group to the keeptime
for $group ( sort (keys %LASTREAD) ) {
($group eq $start_token) && next;
# if some group is specifically defined, skip it
$def = "NOT";
for $d ( @defined ){
if($group =~ /$d/){
if($debug){
$d1 = $d;
if($d1 =~ /\.[*+?]/){
$d1 =~ s/\.([*+?])/$1/g;
}
$warn .= "Drop: $group, implied by $d1\n";
}
$def = "Yes";
}
if( $def eq "Yes" ) { last;}
}
if( $def eq "Yes" ) {
next;
}
$diff = $now - $LASTREAD{$group};
if($diff <= $keeptime){
if($group =~ /binaries|pictures/){
print EXP_NEW "$group:A:1:$bindefault:$purge\n";
} else {
print EXP_NEW "$group:A:1:$default:$purge\n";
}
$total++;
} else {
if($debug){
$warn .= "Drop: $group, inactive for $default days\n";
}
delete $LASTREAD{$group};
}
}
# get the number of entries in the database
$groups = (keys %LASTREAD) - 1;
print EXP_NEW "## Total: $total/$groups groups processed\n";
print EXP_NEW "\n$end\n## Do not put anything after this line ###\n";
close(EXP_NEW); dbmclose(LASTREAD);
if($debug){
$warn .= "## Total: $total/$groups groups processed\n";
}
if ($opt_m) {
# mail the result to the news owner
system "$mail < $expire_new";
}
if($now - $start_time > $wait && ! $debug){
system "mv $expire $expire.$day; mv $expire_new $expire";
} else {
$warn .= "Collecting group information only, $expire intacted.\n";
$warn .= "Expire list is in $expire.new\n";
}
if ($do_hosts) {
# flush the hostslog file
system "mv -f $hostslog $hostslog.$day";
open(HOSTSLOG, ">$hostslog");
$hosts = (keys %hostslog);
if($debug){ $warn .= "\nHost access log: $hosts hosts\n\n";}
foreach $host ( sort keys %hostslog ){
printf HOSTSLOG "%-25s $hostslog{$host}\n", "$host:";
if($debug){
$warn .= sprintf("%-25s $hostslog{$host}\n", "$host:");
}
}
}
if($warn){ print "\nMessage from $progname:\n$warn";}
exit;
########### Change Log ####################################
#
# 8/Aug/94:
# Bug: reported by hagberg@mail.med.cornell.edu:
# when something like '*binaries*' appears in the expire.ctl
# actgroups will complain because it is not a legal regexp
# for perl
# fix: change the '*','+','?' appear in the pattern to '.*','.+'
# and '.+' before compare with the group names.
# 11/Aug/94:
# Add: Hosts.log file to log the hosts accessing our server and its
# last access time
# 17/Aug/94:
# Add: delete entries from the database if the groups are not active
# for more than $default days
#
# 18/Aug/94:(Ver 0.03b, 18 August 1994)
# Bug: reported by Tim Rosmus <tim@mdd.comm.mot.com>:
# if the expire line contains never, that line was not got into
# the @defined array. Fixed.
# Add: Three more options (patches from tim@mdd.comm.mot.com)
# -d, -h, -m
Technical Details
Message-ID:
<32vi4p$5uk@niaomi.iscm.ulst.ac.uk>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.admin.mbox.zip!bga.com!news.sprintlink.net!hookup!swrinde!pipex!sunic!trane.uninett.no!eunet.no!nuug!EU.net!uunet!news.iscm.ulst.ac.uk!kim.iscm.ulst.ac.uk!yufanShow Full Headers
Complete Article Headers
Message-ID: <32vi4p$5uk@niaomi.iscm.ulst.ac.uk> Subject: New version of actgroups: Automatic tuning the expire.ctl Date: Thu, 18 Aug 1994 11:54:01 +0000 From: yufan@iscm.ulst.ac.uk (Yufan Hu) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.admin.mbox.zip!bga.com!news.sprintlink.net!hookup!swrinde!pipex!sunic!trane.uninett.no!eunet.no!nuug!EU.net!uunet!news.iscm.ulst.ac.uk!kim.iscm.ulst.ac.uk!yufan Newsgroups: news.admin.misc,news.software.nntp,news.admin Organization: Interactive Systems Centre, University of Ulster Lines: 464 Distribution: inet NNTP-Posting-Host: kim.iscm.ulst.ac.uk Keywords: administration,expire X-Newsreader: TIN [version 1.2 PL2]