Re: benchmarking i/o throughput
Andreas Schäfer <[email protected]>
| Newsgroups | gmane.linux.cluster.openmosix.general |
|---|---|
| Message-ID | <20060221164538.GA31487@wintermute> |
On 11:59 Tue 21 Feb , Jeroen Demeyer wrote: > What happens if you replace > std::cout.write(buf, BUF_SIZE); > with the syscall > write(1, buf, BUF_SIZE); > C++ tends to break up writes into small pieces, so this could affect performance. Hmm, I should have thought of that myself, but still no good: the rate stays as low as 90k/s. I've modified my initial setup and when writing directly to /dev/zero I get the expected rate net bandwith. It drops again: > ./writeTest 16 30 >/dev/zero sleeping 30 seconds dumping 16 mega bytes write took 1368 milli seconds 11.9766 MB/s > ./writeTest 1 30 >/tmp/test sleeping 30 seconds dumping 1 mega bytes write took 11283 milli seconds 0.090756 MB/s The attached writeTest.cpp uses directly the write() syscall, so I assume it's got to do with how the syscall is handled on the home machine. -Andreas
writeTest.cpp
(text/plain, 1.2 KB)
#include <iostream>
#include <sstream>
#include <string>
#include <sys/time.h>
#define BUF_SIZE 524288
void
dump(int megaBytes) {
char buf[BUF_SIZE];
for (int i = 0; i < BUF_SIZE; i++) {
buf[i] = 'a';
}
for (int i = 0; i < megaBytes; i++) {
for (int c = 0; c < 1024*1024/BUF_SIZE; c++) {
write(1, buf, BUF_SIZE);
}
}
}
int
str2int(std::string str) {
std::istringstream conv(str);
int res;
conv >> res;
return res;
}
int
main(int argc, char **argv) {
if (argc != 3) {
std::cerr << "usage: ./writeTest megaBytes sleepTime\n";
return 1;
}
int megaBytes = str2int(argv[1]);
int sleepTime = str2int(argv[2]);
struct timeval tBegin;
struct timeval tEnd;
struct timezone tz;
std::cerr << "sleeping " << sleepTime << " seconds\n";
sleep(sleepTime);
std::cerr << "dumping " << megaBytes << " mega bytes\n";
gettimeofday(&tBegin,&tz);
dump(megaBytes);
gettimeofday(&tEnd,&tz);
int milliSpan = (tEnd.tv_sec - tBegin.tv_sec) * 1000 + (tEnd.tv_usec - tBegin.tv_usec) / 1000;
std::cerr << "write took " << milliSpan << " milli seconds\n";
std::cerr << (megaBytes*1024.0/milliSpan) << " MB/s\n";
return 0;
}