« Plesk 8.1.1 Upgrade | Main | Plesk 8.1.1 Upgrade Part 2 »

Network Traffic

I finally got around to doing some simple network stats. Our VPS is on a 1.5Mbps connection, and there are times I wonder if we're pushing the limit. I had tried to estimate this from by our http log files. But using /proc/net/dev instead is much simpler and much more accurate.

/proc/net/dev is part of the /proc file subsystem which provides an interface into various kernel components. In this case the network devices.

cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:1151927274 1230341923    0    0    0     0          0         0 1106834891 1631490609    0    0    0     0       0          0
venet0:1441578760 14564083    0    0    0     0          0         0 3288360012 16648575    0    0    0     0       0          0

As you can see, /proc/net/dev is just a file. But the great part is that is provides a real-time interface into the network stats I want to know. Specifically the number of bytes sent and received over the internet: the "venet0" interface in this case.

I took my cpu_stat.pl program that used vmstat to save CPU stats and modified it to create procnetdev.pl to save network stats. It captures the contents of /proc/net/dev, specifically the line that begins "venet0:".

use DBI;
use strict;
my $user = 'some_user';
my $password = 'some_passwd';
my $dsn = 'DBI:mysql:cpu_stat:localhost';
my $dbh = DBI->connect($dsn, $user, $password,
                      { RaiseError => 1, AutoCommit => 0 })
   or die "Couldn't connect to database: " . DBI->errstr;
my $insert_cpu =
            $dbh->prepare_cached("INSERT INTO pnetdev VALUES (CURRENT_TIMESTAMP,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

my $net_stat = `cat /proc/net/dev`;

$net_stat =~ m/venet0:(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/ ;

$insert_cpu->execute($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
        or die "Couldn't insert row into pnetdev table: " . DBI->errstr;


I used phpMyAdmin to create the "pnetdev" table, but I made sure the number of bytes sent/received were "bigint" datatypes since they're already large values. I think /proc/net/dev simply keeps a record of total number of bytes sent/received since the last reboot, so those numbers could get really big.

I then set up a CRON entry to run this program every minute. I set it running yesterday and the results this morning are interesting. First of all, it looks like the number of bytes is actually 32bit since the sent bytes field reached 4293591390 before rolling over to 379609. The most useful thing would appear to be that our VPS isn't doing more than 50,000 bytes/sec.

Bytes/Second Graph

Our VPS has a 1.5 Mbps connection, or 1.5 million bits per sec, or 187500 bytes per sec. I'm curious to see how close we get to that limit, and whether we can actually reach it. Today should be a good test as we sent out our newsletter last night and it will drive a lot of traffic to our site. We've noticed performance problems in the past, like slow response times, so it will be interesting to see if this is network related.

UPDATE: I just did a file download of 4.78MB. It took 1 min 8 sec and reported a download speed of 72KB/sec. Checking my network stats I could see a spike up to 171048 bytes/sec average for one minute during that download period. This indicates that I can get pretty close to the 187500 bytes/sec bandwidth cap, and that the current VPS is ok with a 1.5Mbps connection. But it's probably worth monitoring as on busy days it looks like I'm getting 50-60KB/sec normal throughput. This is about one third of our capacity.

Network Traffic May 9 2007

UPDATE #2 - I wasn't totally satisfied with that test so I downloaded a 123mb file on a 11Mpbs connection. This took 16min 10sec and averaged 138KB/sec. But the interesting part is my network stats show an average 178660 bytes/sec, pretty close to my maximum. The other interesting thing is that our web sites still seemed responsive. Also CPU usage was minimal. So I'm guessing that it's going to take a lot of regular concurrent visitors and/or multiple concurrent file downloads to overload the 1.5Mbps connection. Just filling it once in a while isn't much cause for concern. I think it would have to stay filled for extended periods of time (or exhibit a slow browsing experience) to bother upgrading to the next level (3Mbps).

© 2016 Mike Silversides


This page contains a single entry from the blog posted on May 8, 2007 12:14 PM.

The previous post in this blog was Plesk 8.1.1 Upgrade.

The next post in this blog is Plesk 8.1.1 Upgrade Part 2.

Many more can be found on the main index page or by looking through the archives.