🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
1 messages
1 total messages Started by Yufan Hu Mon, 08 Aug 1994 16:35
Automate the tuning of expire policy
#2780
Author: Yufan Hu
Date: Mon, 08 Aug 1994 16:35
384 lines
12879 bytes
Hi, news administrators, 

Here is my script for automatically tuning the expire.ctl for fine-grained
expire control, as promised a few days ago. Suggestions and comments are
welcome.

Yufan Hu.

---------------------------------------------------------------------------
	actgroups -- Automating news group expiring policy.

1. The problem.

	I am a news administrator in a small site. We cannot afford a big disk
	to carry all the news groups for long.

	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.
		to let the users explicitly request for some groups to be kept
			longer

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 accrodingly. 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 scan the database, and compare 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 extry 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.

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
		some times make 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.

	Conclusion: with actgroups I can run the news server with 800 more groups and
		200 MB less disk space.


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.



Here comes the real stuff:
===============  Cut Here ====================================================
#!/usr/local/bin/perl
# Active Groups -- Detecting actively accessed news groups and setting 
#		expire.ctl accordingly
$progname 	= 	"actgroups";
$version 	= 	"Ver 0.02, 7 August 1994";
$author 	= 	"Yufan Hu <Y.Hu@ulst.ac.uk>";
# 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
#
# 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
###############################################################

$LastRead = "/usr/local/news/LastRead.log";
$newslog = "/var/log/news/news.notice";
$expire = "/usr/local/news/expire.ctl";

# $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 10 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;

# 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;


################# Debug Only #################################
$debug = 1;
#################################################################
# Anything below should not need to be changed

while(@ARGV){
	if($ARGV[0] eq '-l'){
		shift @ARGV;
		if(@ARGV){
			$newslog = $ARGV[0];
			shift @ARGV;
		}
	}
}

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;

# scan through the log file, detecting any accessed groups within current day
# and store the current time in the database

while(<LOG>) {
	if(/.*nnrpd.* group ([^\s]+)\s\d+/){
		$group = $1;
		if( $debug && (! $LASTREAD{$group}) ){
			$warn .= "Adding:  	$group\n";
		}
		$LASTREAD{$group} = $now;
	}
}

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+):(\d+):(\d+)/){
			$group = $1;
			if($group eq '*'){
				if($3 != 1 || $4 != 1 || $5 !=1){
					print EXP_NEW "##$_";
					print EXP_NEW "*:$2:1:1:1\n";
					next;
				} 
			} else {
				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){ 
				$warn .= "$group <= $d\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++;
	} elsif($debug){
		$warn .= "Removing:	$group\n";
	}
}

# 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";
}
# mail the result to the news owner
#system "$mail < $expire_new";

if($now - $start_time > $wait){
	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($warn){ print "\nMessage from $progname:\n$warn";}
exit;


Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads