a trick with perl

Jason A. Smith jazbo at jazbo.dyndns.org
Fri Jan 9 13:12:38 CET 2004


On Fri, 2004-01-09 at 03:35, Chris Fortune wrote:
> After some major quality time with my manuals, I discovered how to create a
> RAM device, create temporary files in it, and feed them to bogofilter (and
> several other filters via the command line).  If you are the owner of a
> disc-bound system with plenty of RAM, this trick could be very useful.  Here
> is the code to create a RAM disc (as root):
> 
> dd if=/dev/zero of=/dev/ram0 count=1440 bs=1024
> mke2fs /dev/ram0
> mkdir /home/username/mnt
> mount /dev/ram0 /home/username/mnt
> chown username /home/username/mnt   # so that 'username's scripts can read
> and write to it
> ls -al /home/username/mnt

There is an easier/better way to create an in RAM only filesystem on
linux, use tmpfs and add a line like this to /etc/fstab:

none  /mount/point  tmpfs  size=5M,mode=755,uid=user,gid=user  0 0

This filesystem is actually located in virtual memory space and can be
swapped out when not being used.  Read the kernel documentation for more
information:

/usr/src/linux/Documentation/filesystems/tmpfs.txt

> What I found most surprising on my system was that the RAM device was *not*
> much faster than simply creating a file on disc.

This is because all file transactions are buffered in memory first.  The
only advantage of using the RAM filesystem is that it will never have to
be synced to the disk, as long as it is kept busy.  Since you are
usually size restricted in how big you can make this filesystem, you
will gain if there are constantly a lot of read and/or write
transactions to that filesystem, so using this method will keep your
disk from thrashing and always give you quick access to the data there.

> # ave. time to open, print 4kb data, close and unlink a file (1000 trials)
> # using disc filesystem: 0.0000653883333333333 secs.
> # using RAM device:   0.0000510116666666673 secs
> 
> I have dual scsi raid, which is apparantly pretty fast. The RAM device is
> only about 22% faster, but I suppose it makes a difference as the months go
> by, so I may as well use it, now that it's set up.:
> 
>         # create temporary file
>         $temp_file = "/home/username/mnt/" . rand(100) . "\.tmp";
>         print "$temp_file\n" if $DEBUG;
>         open TEMP, ">$temp_file" or die $!;
>         print TEMP $email_contents;
>         close TEMP;
> 
>         # BogoFilter
>         $bf = `bogofilter -T < $temp_file`;  # ahhh, so easy.  No messy
> pipes
>         print "BogoFilter response:  $bf\n";
> 
>         # Vipul's Razor
>         ... etc...
>         # ClamAV
>         ... etc...
>         # Pyzor
>         ... etc...
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> FAQ: http://bogofilter.sourceforge.net/bogofilter-faq.html
> To unsubscribe, e-mail: bogofilter-unsubscribe at aotto.com
> For summary digest subscription: bogofilter-digest-subscribe at aotto.com
> For more commands, e-mail: bogofilter-help at aotto.com
> 




More information about the Bogofilter mailing list