ceph/src/streamtest.cc

148 lines
3.0 KiB
C++
Raw Normal View History

2008-01-23 18:49:54 +00:00
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#define dout(x) if (x <= g_conf.debug_ebofs) *_dout << dbeginl
2008-01-23 18:49:54 +00:00
#include <iostream>
#include "ebofs/Ebofs.h"
2008-05-20 19:11:56 +00:00
#include "os/FileStore.h"
2008-01-23 18:49:54 +00:00
2008-01-25 05:59:38 +00:00
struct io {
utime_t start, ack, commit;
bool done() {
return ack.sec() && commit.sec();
}
};
map<off_t,io> writes;
2008-01-23 18:49:54 +00:00
2008-10-31 22:01:09 +00:00
Mutex lock("streamtest.cc lock");
2008-01-25 05:59:38 +00:00
void pr(off_t off)
{
io &i = writes[off];
2008-04-22 20:20:38 +00:00
dout(2) << off << "\t"
2008-01-25 05:59:38 +00:00
<< (i.ack - i.start) << "\t"
<< (i.commit - i.start) << dendl;
writes.erase(off);
}
void set_start(off_t off, utime_t t)
{
Mutex::Locker l(lock);
writes[off].start = t;
}
void set_ack(off_t off, utime_t t)
{
Mutex::Locker l(lock);
writes[off].ack = t;
if (writes[off].done())
pr(off);
}
void set_commit(off_t off, utime_t t)
{
Mutex::Locker l(lock);
writes[off].commit = t;
if (writes[off].done())
pr(off);
}
2008-01-23 18:49:54 +00:00
struct C_Commit : public Context {
off_t off;
C_Commit(off_t o) : off(o) {}
void finish(int r) {
Mutex::Locker l(lock);
2008-01-25 05:59:38 +00:00
set_commit(off, g_clock.now());
2008-01-23 18:49:54 +00:00
}
};
int main(int argc, const char **argv)
{
vector<const char*> args;
argv_to_vec(argc, argv, args);
parse_config_options(args);
// args
if (args.size() < 3) return -1;
2008-01-23 18:49:54 +00:00
const char *filename = args[0];
int seconds = atoi(args[1]);
int bytes = atoi(args[2]);
const char *journal = 0;
if (args.size() >= 4)
journal = args[3];
2008-01-23 18:49:54 +00:00
buffer::ptr bp(bytes);
bp.zero();
bufferlist bl;
bl.push_back(bp);
float interval = 1.0 / 1000;
2008-01-23 18:49:54 +00:00
cout << "#dev " << filename
<< ", " << seconds << " seconds, " << bytes << " bytes per write" << std::endl;
2008-01-23 18:49:54 +00:00
2008-09-11 17:56:16 +00:00
ObjectStore *fs = new Ebofs(filename, journal);
//ObjectStore *fs = new FileStore(filename);
if (g_conf.mkfs &&
fs->mkfs() < 0) {
2008-01-23 18:49:54 +00:00
cout << "mkfs failed" << std::endl;
return -1;
}
if (fs->mount() < 0) {
2008-01-23 18:49:54 +00:00
cout << "mount failed" << std::endl;
return -1;
}
ObjectStore::Transaction ft;
ft.create_collection(0);
fs->apply_transaction(ft);
2008-01-23 18:49:54 +00:00
utime_t now = g_clock.now();
utime_t end = now;
end += seconds;
off_t pos = 0;
//cout << "stop at " << end << std::endl;
cout << "# offset\tack\tcommit" << std::endl;
while (now < end) {
pobject_t poid(0, 0, object_t(1, 1));
2008-01-25 05:59:38 +00:00
utime_t start = now;
set_start(pos, now);
2008-04-22 20:20:38 +00:00
ObjectStore::Transaction t;
t.write(0, poid, pos, bytes, bl);
2008-04-22 20:20:38 +00:00
fs->apply_transaction(t, new C_Commit(pos));
2008-01-23 18:49:54 +00:00
now = g_clock.now();
2008-01-25 05:59:38 +00:00
set_ack(pos, now);
2008-01-23 18:49:54 +00:00
pos += bytes;
// wait?
utime_t next = start;
next += interval;
if (now < next) {
float s = next - now;
s *= 1000 * 1000; // s -> us
//cout << "sleeping for " << s << " us" << std::endl;
usleep((int)s);
}
2008-01-23 18:49:54 +00:00
}
fs->umount();
2008-01-23 18:49:54 +00:00
}