patch 4.0
This commit is contained in:
@ -13,7 +13,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "lib/allocator/ob_malloc.h"
|
||||
#include "lib/queue/ob_priority_queue.h"
|
||||
#include "lib/coro/co.h"
|
||||
#include "lib/thread/thread_pool.h"
|
||||
#include <iostream>
|
||||
|
||||
@ -21,28 +20,25 @@ using namespace oceanbase::lib;
|
||||
using namespace oceanbase::common;
|
||||
using namespace std;
|
||||
|
||||
class TestQueue : public ThreadPool {
|
||||
class TestQueue: public ThreadPool
|
||||
{
|
||||
public:
|
||||
enum { BATCH = 64 };
|
||||
struct QData : public ObLink {
|
||||
QData() : val_(0)
|
||||
{}
|
||||
QData(int64_t x) : val_(x)
|
||||
{}
|
||||
~QData()
|
||||
{}
|
||||
struct QData: public ObLink
|
||||
{
|
||||
QData(): val_(0) {}
|
||||
QData(int64_t x): val_(x) {}
|
||||
~QData() {}
|
||||
int64_t val_;
|
||||
};
|
||||
typedef ObPriorityQueue2<1, 2> Queue;
|
||||
TestQueue(): push_seq_(0), pop_seq_(0)
|
||||
{
|
||||
limit_ = atoll(getenv("limit")?: "1000000");
|
||||
TestQueue(): push_seq_(0), pop_seq_(0) {
|
||||
limit_ = atoll(getenv("limit")?: "100000");
|
||||
}
|
||||
virtual ~TestQueue()
|
||||
{}
|
||||
virtual ~TestQueue() {}
|
||||
void do_stress()
|
||||
{
|
||||
set_thread_count(atoi(getenv("n_thread") ?: "8"));
|
||||
set_thread_count(atoi(getenv("n_thread")?: "8"));
|
||||
n_pusher_ = atoi(getenv("n_pusher")?: "4");
|
||||
queue_.set_limit(65536);
|
||||
int ret = OB_SUCCESS;
|
||||
@ -56,26 +52,23 @@ public:
|
||||
void print()
|
||||
{
|
||||
int64_t last_seq = ATOMIC_LOAD(&pop_seq_);
|
||||
while (ATOMIC_LOAD(&pop_seq_) < limit_) {
|
||||
while(ATOMIC_LOAD(&pop_seq_) < limit_) {
|
||||
sleep(1);
|
||||
int64_t cur_seq = ATOMIC_LOAD(&pop_seq_);
|
||||
LIB_LOG(INFO, "queue", "tps", BATCH * (cur_seq - last_seq));
|
||||
last_seq = cur_seq;
|
||||
}
|
||||
}
|
||||
int64_t get_seq(int64_t &seq)
|
||||
{
|
||||
int64_t get_seq(int64_t &seq) {
|
||||
return ATOMIC_FAA(&seq, 1);
|
||||
}
|
||||
int insert(int64_t seq)
|
||||
{
|
||||
int insert(int64_t seq) {
|
||||
int err = 0;
|
||||
QData* data = new QData(seq);
|
||||
err = queue_.push(data, data->val_ % 3);
|
||||
return err;
|
||||
}
|
||||
int del(uint64_t idx)
|
||||
{
|
||||
int del(uint64_t idx) {
|
||||
int err;
|
||||
QData* data = NULL;
|
||||
if (idx == 0) {
|
||||
@ -101,34 +94,31 @@ public:
|
||||
const uint64_t idx = get_thread_idx();
|
||||
cout << "idx: " << idx << endl;
|
||||
if (idx >= get_thread_count() - n_pusher_) {
|
||||
while ((seq = get_seq(push_seq_)) < limit_) {
|
||||
for (int i = 0; i < BATCH; i++) {
|
||||
while((seq = get_seq(push_seq_)) < limit_) {
|
||||
for(int i = 0; i < BATCH; i++) {
|
||||
//::usleep(10000);
|
||||
auto now = ObTimeUtility::current_time();
|
||||
do {
|
||||
ret = insert(now);
|
||||
} while (OB_FAIL(ret));
|
||||
do { ret = insert(now); } while (OB_FAIL(ret));
|
||||
}
|
||||
}
|
||||
stop_ = true;
|
||||
} else {
|
||||
while ((seq = get_seq(pop_seq_)) < limit_) {
|
||||
for (int i = 0; i < BATCH; i++) {
|
||||
do {
|
||||
ret = del(idx);
|
||||
} while (OB_FAIL(ret));
|
||||
while((seq = get_seq(pop_seq_)) < limit_) {
|
||||
for(int i = 0; i < BATCH; i++) {
|
||||
do { ret = del(idx); } while (OB_FAIL(ret) && !stop_);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << idx << " finished" << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
int64_t push_seq_ CACHE_ALIGNED;
|
||||
int64_t pop_seq_ CACHE_ALIGNED;
|
||||
int64_t limit_;
|
||||
int64_t n_pusher_;
|
||||
Queue queue_;
|
||||
}; // end of class Consumer
|
||||
bool stop_ = false;
|
||||
}; // end of class Consumer
|
||||
|
||||
TEST(TestPriorityQueue, WithCoro)
|
||||
{
|
||||
@ -136,10 +126,10 @@ TEST(TestPriorityQueue, WithCoro)
|
||||
tq.do_stress();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
oceanbase::common::ObLogger::get_logger().set_log_level("debug");
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
// testing::FLAGS_gtest_filter = "DO_NOT_RUN";
|
||||
testing::InitGoogleTest(&argc,argv);
|
||||
//testing::FLAGS_gtest_filter = "DO_NOT_RUN";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user