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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2009-05-06 18:56:08 +00:00
|
|
|
//#include "ebofs/Ebofs.h"
|
2008-05-20 19:11:56 +00:00
|
|
|
#include "os/FileStore.h"
|
2009-02-09 23:46:02 +00:00
|
|
|
#include "common/common_init.h"
|
2011-02-20 17:18:03 +00:00
|
|
|
#include "common/ceph_argparse.h"
|
2008-01-23 18:49:54 +00:00
|
|
|
|
2008-11-05 22:53:53 +00:00
|
|
|
#undef dout_prefix
|
2010-12-08 06:40:28 +00:00
|
|
|
#define dout_prefix *_dout
|
2008-11-05 22:53:53 +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;
|
2010-01-30 00:36:10 +00:00
|
|
|
Cond cond;
|
2008-10-31 22:01:09 +00:00
|
|
|
Mutex lock("streamtest.cc lock");
|
2008-01-25 04:38:15 +00:00
|
|
|
|
2010-01-30 00:36:10 +00:00
|
|
|
unsigned concurrent = 1;
|
|
|
|
void throttle()
|
|
|
|
{
|
|
|
|
Mutex::Locker l(lock);
|
|
|
|
while (writes.size() >= concurrent) {
|
|
|
|
//generic_dout(0) << "waiting" << dendl;
|
|
|
|
cond.Wait(lock);
|
|
|
|
}
|
|
|
|
}
|
2008-01-25 05:59:38 +00:00
|
|
|
void pr(off_t off)
|
|
|
|
{
|
|
|
|
io &i = writes[off];
|
2010-01-30 00:36:10 +00:00
|
|
|
generic_dout(0) << off << "\t"
|
2008-01-25 05:59:38 +00:00
|
|
|
<< (i.ack - i.start) << "\t"
|
|
|
|
<< (i.commit - i.start) << dendl;
|
|
|
|
writes.erase(off);
|
2010-01-30 00:36:10 +00:00
|
|
|
cond.Signal();
|
2008-01-25 05:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2010-01-30 00:36:10 +00:00
|
|
|
//generic_dout(0) << "ack " << off << dendl;
|
2008-01-25 05:59:38 +00:00
|
|
|
writes[off].ack = t;
|
|
|
|
if (writes[off].done())
|
|
|
|
pr(off);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_commit(off_t off, utime_t t)
|
|
|
|
{
|
|
|
|
Mutex::Locker l(lock);
|
2010-01-30 00:36:10 +00:00
|
|
|
//generic_dout(0) << "commit " << off << dendl;
|
2008-01-25 05:59:38 +00:00
|
|
|
writes[off].commit = t;
|
|
|
|
if (writes[off].done())
|
|
|
|
pr(off);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 00:36:10 +00:00
|
|
|
struct C_Ack : public Context {
|
|
|
|
off_t off;
|
|
|
|
C_Ack(off_t o) : off(o) {}
|
|
|
|
void finish(int r) {
|
|
|
|
set_ack(off, g_clock.now());
|
|
|
|
}
|
|
|
|
};
|
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) {
|
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);
|
2008-11-05 22:53:53 +00:00
|
|
|
env_to_vec(args);
|
2010-07-01 16:25:43 +00:00
|
|
|
|
2011-03-09 16:44:05 +00:00
|
|
|
common_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY);
|
|
|
|
keyring_init(&g_conf);
|
2008-01-23 18:49:54 +00:00
|
|
|
|
|
|
|
// args
|
2008-01-24 09:47:03 +00:00
|
|
|
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]);
|
2008-01-24 09:47:03 +00:00
|
|
|
const char *journal = 0;
|
|
|
|
if (args.size() >= 4)
|
|
|
|
journal = args[3];
|
2010-01-30 00:36:10 +00:00
|
|
|
if (args.size() >= 5)
|
|
|
|
concurrent = atoi(args[4]);
|
|
|
|
|
|
|
|
cout << "concurrent = " << concurrent << std::endl;
|
2008-01-23 18:49:54 +00:00
|
|
|
|
|
|
|
buffer::ptr bp(bytes);
|
|
|
|
bp.zero();
|
|
|
|
bufferlist bl;
|
|
|
|
bl.push_back(bp);
|
|
|
|
|
2010-01-30 00:36:10 +00:00
|
|
|
//float interval = 1.0 / 1000;
|
2008-01-25 04:38:15 +00:00
|
|
|
|
2008-01-23 18:49:54 +00:00
|
|
|
cout << "#dev " << filename
|
2008-06-10 22:06:56 +00:00
|
|
|
<< ", " << seconds << " seconds, " << bytes << " bytes per write" << std::endl;
|
2008-01-23 18:49:54 +00:00
|
|
|
|
2009-05-06 18:56:08 +00:00
|
|
|
//ObjectStore *fs = new Ebofs(filename, journal);
|
2010-01-30 00:36:10 +00:00
|
|
|
ObjectStore *fs = new FileStore(filename, journal);
|
2008-03-04 05:46:23 +00:00
|
|
|
|
|
|
|
if (fs->mount() < 0) {
|
2008-01-23 18:49:54 +00:00
|
|
|
cout << "mount failed" << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-09-12 18:44:23 +00:00
|
|
|
ObjectStore::Transaction ft;
|
2009-11-04 20:24:39 +00:00
|
|
|
ft.create_collection(coll_t());
|
2008-09-12 18:44:23 +00:00
|
|
|
fs->apply_transaction(ft);
|
2008-06-10 22:06:56 +00:00
|
|
|
|
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) {
|
2009-06-03 20:48:58 +00:00
|
|
|
sobject_t poid(object_t("streamtest"), 0);
|
2010-01-30 00:36:10 +00:00
|
|
|
|
|
|
|
set_start(pos, g_clock.now());
|
|
|
|
ObjectStore::Transaction *t = new ObjectStore::Transaction;
|
|
|
|
t->write(coll_t(), poid, pos, bytes, bl);
|
2010-03-02 23:09:24 +00:00
|
|
|
fs->queue_transaction(NULL, t, new C_Ack(pos), new C_Commit(pos));
|
2008-01-23 18:49:54 +00:00
|
|
|
pos += bytes;
|
2008-01-25 04:38:15 +00:00
|
|
|
|
2010-01-30 00:36:10 +00:00
|
|
|
throttle();
|
|
|
|
|
2008-01-25 04:38:15 +00:00
|
|
|
// wait?
|
2010-01-30 00:36:10 +00:00
|
|
|
/*
|
2008-01-25 04:38:15 +00:00
|
|
|
utime_t next = start;
|
|
|
|
next += interval;
|
|
|
|
if (now < next) {
|
|
|
|
float s = next - now;
|
|
|
|
s *= 1000 * 1000; // s -> us
|
2008-03-04 19:06:50 +00:00
|
|
|
//cout << "sleeping for " << s << " us" << std::endl;
|
|
|
|
usleep((int)s);
|
2008-01-25 04:38:15 +00:00
|
|
|
}
|
2010-01-30 00:36:10 +00:00
|
|
|
*/
|
2008-01-23 18:49:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-04 05:46:23 +00:00
|
|
|
fs->umount();
|
2008-01-23 18:49:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|