Date: Thu, 15 Jul 1999 11:00:11 -0600 (MDT) From: "Ronald G. Minnich" <rminnich@acl.lanl.gov> To: hackers@freebsd.org Subject: Another take on /proc statistics (joke of the day) Message-ID: <Pine.LNX.4.10.9907151055280.11756-100000@tbp.acl.lanl.gov>
next in thread | raw e-mail | index | archive | help
I thought this amusing.
Take the following program, designed to suck stats out of /proc for the
network devices:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
main()
{
char stuff[4096];
int fd = open("/proc/net/dev", 0);
while(1)
{
int amount = read(fd, stuff, sizeof(stuff));
if (amount > 0)
write(1, stuff, amount);
sleep(1);
lseek(fd, (off_t) 0, SEEK_SET);
}
}
Run this on linux, and you'll get the same values for all the stats.
how to make it work right?
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
main()
{
char stuff[4096];
while(1)
{
int fd = open("/proc/net/dev", 0);
int amount;
amount = read(fd, stuff, sizeof(stuff));
if (amount > 0)
write(1, stuff, amount);
close(fd);
sleep(1);
}
}
What are the implications of this? Well, if you have an rstatd that uses
/proc for statistics, it will have to (for every request) open the status
files, read them, and close them. Net result: very very poor performance
for an rstatd (not even counting the fact that the rstatd has to parse
formatted output back to a binary format ...)
ron
p.s. the rstatd I have for redhat does indeed read stats out of /proc ...
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.10.9907151055280.11756-100000>
