예제 #1
0
inline void MDS_REQUEST_START(const std::string& method, const uint64_t& instance_id) {
    HANDY_COUNTER_INCREMENT(("mds.%s", method.c_str()));

    HANDY_TIMER_START(("mds.%s.time", method.c_str()), instance_id);

    HANDY_TIMER_START(("mds.%s.reply.time", method.c_str()), instance_id);
}
예제 #2
0
파일: load.cpp 프로젝트: noxiouz/handystats
// command() function is executed in multiple threads
// NOTE: rand() function may be not thread-safe.
void command() {
	// 0 .. counters .. counters + gauges .. counters + gauges + timers
	const double total_metrics = counters + gauges + timers;

	double counter_prob = double(counters) / total_metrics;
	double gauge_prob = double(counters + gauges) / total_metrics;
//	double timer_prob = 1.0;

	double choice = double(rand()) / RAND_MAX;

	if (handystats::math_utils::cmp(choice, counter_prob) < 0) {
		HANDY_COUNTER_INCREMENT(("load_test.counter.%d", rand() % counters), rand());
	}
	else if (handystats::math_utils::cmp(choice, gauge_prob) < 0) {
		HANDY_GAUGE_SET(("load_test.gauge.%d", rand() % gauges), rand());
	}
	else {
		if (rand() & 1) {
			HANDY_TIMER_START(("load_test.timer.%d", rand() % timers), std::hash<std::thread::id>()(std::this_thread::get_id()));
		}
		else {
			HANDY_TIMER_STOP(("load_test.timer.%d", rand() % timers), std::hash<std::thread::id>()(std::this_thread::get_id()));
		}
	}
}
예제 #3
0
파일: test.c 프로젝트: noxiouz/handystats
void run_test_timer(void) {
	struct timespec rqtp;
	rqtp.tv_sec = 0;
	rqtp.tv_nsec = TEST_TIMER_NANOSLEEP_TIME;

	int cycle;

	for (cycle = 0; cycle < TEST_TIMER_NANOSLEEP_COUNT; ++cycle) {
		HANDY_TIMER_START(("%s." TEST_TIMER_NAME, "test"), cycle);
	}

	nanosleep(&rqtp, NULL);

	for (cycle = 0; cycle < TEST_TIMER_NANOSLEEP_COUNT; ++cycle) {
		HANDY_TIMER_STOP(("%s." TEST_TIMER_NAME, "test"), cycle);
	}
}
예제 #4
0
void proxy::req_delete::on_request(const ioremap::thevoid::http_request &req, const boost::asio::const_buffer &buffer) {
	HANDY_TIMER_START("mds.delete.time", reinterpret_cast<uint64_t>(this));
	HANDY_MDS_DELETE();
	try {
		BH_LOG(logger(), SWARM_LOG_INFO, "Delete: handle request: %s", req.url().path().c_str());
		namespace_ptr_t ns;
		url_str = req.url().path();
		try {
			ns = server()->get_namespace(url_str, "/delete");

			auto &&prep_session = server()->prepare_session(url_str, ns);
			session.reset(prep_session.first);
			key = prep_session.second;
		} catch (const std::exception &ex) {
			BH_LOG(logger(), SWARM_LOG_INFO,
				"Delete: request = \"%s\", err = \"%s\"",
				url_str.c_str(), ex.what()
				);
			HANDY_MDS_DELETE_REPLY(400);
			send_reply(400);
			return;
		}

		if (!server()->check_basic_auth(ns->name, ns->auth_key_for_write, req.headers().get("Authorization"))) {
			auto token = server()->get_auth_token(req.headers().get("Authorization"));
			BH_LOG(logger(), SWARM_LOG_INFO,
					"%s: invalid token \"%s\""
					, url_str.c_str(), token.empty() ? "<none>" : token.c_str());
			ioremap::thevoid::http_response reply;
			ioremap::swarm::http_headers headers;

			reply.set_code(401);
			headers.add("WWW-Authenticate", std::string("Basic realm=\"") + ns->name + "\"");
			headers.add("Content-Length", "0");
			reply.set_headers(headers);
			HANDY_MDS_DELETE_REPLY(reply.code());
			send_reply(std::move(reply));
			return;
		}

		if (session->state_num() < server()->die_limit()) {
			throw std::runtime_error("Too low number of existing states");
		}

		session->set_timeout(server()->timeout.lookup);
		session->set_filter(ioremap::elliptics::filters::positive);
		auto alr = session->quorum_lookup(key);
		alr.connect(wrap(std::bind(&proxy::req_delete::on_lookup,
					shared_from_this(), std::placeholders::_1, std::placeholders::_2)));
	} catch (const std::exception &ex) {
		BH_LOG(logger(), SWARM_LOG_ERROR, "Delete request=\"%s\" error: %s"
				, url_str.c_str(), ex.what());
		HANDY_MDS_DELETE_REPLY(500);
		send_reply(500);
	} catch (...) {
		BH_LOG(logger(), SWARM_LOG_ERROR, "Delete request=\"%s\" error: unknown"
				, url_str.c_str());
		HANDY_MDS_DELETE_REPLY(500);
		send_reply(500);
	}
}
예제 #5
0
void proxy::req_get::on_request(const ioremap::thevoid::http_request &req, const boost::asio::const_buffer &buffer) {
	HANDY_TIMER_START("mds.get.time", reinterpret_cast<uint64_t>(this));
	HANDY_MDS_GET();
	m_beg_time = std::chrono::system_clock::now();
	url_str = req.url().path();
	BH_LOG(logger(), SWARM_LOG_INFO, "Get: handle request: %s", url_str.c_str());
	namespace_ptr_t ns;
	try {
		ns = server()->get_namespace(url_str, "/get");
		auto &&prep_session = server()->prepare_session(url_str, ns);
		m_session = prep_session.first;
		m_session->set_timeout(server()->timeout.read);
		m_key = prep_session.second;
		m_key.transform(*m_session);
		m_key.set_id(m_key.id());
	} catch (const std::exception &ex) {
		BH_LOG(logger(), SWARM_LOG_INFO,
			"Get: request = \"%s\"; err: \"%s\"",
			req.url().path().c_str(), ex.what());
		HANDY_MDS_GET_REPLY(400);
		send_reply(400);
		return;
	}

	if (!server()->check_basic_auth(ns->name, ns->auth_key_for_read, req.headers().get("Authorization"))) {
		auto token = server()->get_auth_token(req.headers().get("Authorization"));
		BH_LOG(logger(), SWARM_LOG_INFO,
				"%s: invalid token \"%s\""
				, url_str.c_str(), token.empty() ? "<none>" : token.c_str());
		ioremap::thevoid::http_response reply;
		ioremap::swarm::http_headers headers;

		reply.set_code(401);
		headers.add("WWW-Authenticate", std::string("Basic realm=\"") + ns->name + "\"");
		headers.add("Content-Length", "0");
		reply.set_headers(headers);
		HANDY_MDS_GET_REPLY(reply.code());
		send_reply(std::move(reply));
		return;
	}

	if (m_session->get_groups().empty()) {
		BH_LOG(logger(), SWARM_LOG_INFO
				, "Get %s: on_request: cannot find couple of groups for the request"
				, url_str.c_str());
		HANDY_MDS_GET_REPLY(404);
		send_reply(404);
		return;
	}

	auto query_list = req.url().query();
	m_offset = get_arg<uint64_t>(query_list, "offset", 0);
	m_size = get_arg<uint64_t>(query_list, "size", 0);
	m_if_modified_since = req.headers().get("If-Modified-Since");
	m_first_chunk = true;
	m_chunk_size = server()->m_read_chunk_size;

	{
		std::ostringstream oss;
		oss << "Get " << m_key.remote() << " " << m_key.to_string()
			<< ": lookup from groups [";
		const auto &groups = m_session->get_groups();
		for (auto bit = groups.begin(), it = bit, end = groups.end(); it != end; ++it) {
			if (it != bit) oss << ", ";
			oss << *it;
		}
		oss << ']';
		auto msg = oss.str();
		BH_LOG(logger(), SWARM_LOG_INFO, "%s", msg.c_str());
	}
	{
		auto ioflags = m_session->get_ioflags();
		m_session->set_ioflags(ioflags | DNET_IO_FLAGS_NOCSUM);
		m_session->set_timeout(server()->timeout.lookup);
		m_session->set_filter(ioremap::elliptics::filters::positive);
		auto alr = m_session->quorum_lookup(m_key);
		alr.connect(wrap(std::bind(&proxy::req_get::on_lookup, shared_from_this(),
					std::placeholders::_1, std::placeholders::_2)));
		m_session->set_ioflags(ioflags);
	}
}