This commit is contained in:
shuxin   zheng 2023-07-31 19:00:06 +08:00
parent d1bf85c81c
commit 6790d2dbd7
4 changed files with 15 additions and 7 deletions

View File

@ -53,6 +53,10 @@ void master_service::on_accept(acl::socket_stream& conn) {
void master_service::run(acl::socket_stream& conn, size_t size) {
std::vector<redis_object*> cache;
for (size_t i = 0; i < 5000000; i++) {
pkv::redis_object* o = new pkv::redis_object(cache, 5000000);
cache.emplace_back(o);
}
pkv::redis_coder parser(cache);
pkv::redis_handler handler(db_, parser, conn);
char buf[size];

View File

@ -30,10 +30,11 @@ redis_coder::~redis_coder() {
void redis_coder::clear() {
for (auto obj : objs_) {
if (cache_.size() < cache_max_) {
obj->reset();
cache_.emplace_back(obj);
obj->reset();
} else {
delete obj;
printf(">>>>coder delete o max=%zd, curr=%zd\n", cache_max_, cache_.size());
delete obj;
}
}
@ -65,9 +66,11 @@ redis_object& redis_coder::create_object() {
if (cache_.empty()) {
obj = new redis_object(cache_, cache_max_);
printf(">>>>>>>>>>>%s-%d<<<<max=%zd<<<\n", __func__ , __LINE__, cache_max_);
} else {
obj = cache_.back();
cache_.pop_back();
//printf(">>>---->>>>>>>>%s-%d<<size=%zd<<<<<\n", __func__ , __LINE__, cache_.size());
}
objs_.emplace_back(obj);

View File

@ -12,7 +12,7 @@ namespace pkv {
class redis_coder {
public:
explicit redis_coder(std::vector<redis_object*>& cache, size_t cache_max = 10000);
explicit redis_coder(std::vector<redis_object*>& cache, size_t cache_max = 5000000);
~redis_coder();
const char* update(const char* data, size_t& len);

View File

@ -29,9 +29,10 @@ void redis_object::set_parent(redis_object* parent) {
void redis_object::reset() {
for (auto obj : objs_) {
if (cache_.size() < cache_max_) {
obj->reset();
cache_.emplace_back(obj);
obj->reset();
} else {
printf(">>>>delete o max=%zd, curr=%zd\n", cache_max_, cache_.size());
delete obj;
}
}
@ -130,8 +131,8 @@ const char* redis_object::parse_object(const char* data, size_t& len) {
obj_->set_parent(this);
} else {
obj_ = cache_.back();
obj_->set_parent(this);
cache_.pop_back();
obj_->set_parent(this);
}
return data;
@ -291,8 +292,8 @@ const char* redis_object::parse_arlen(const char* data, size_t& len) {
obj_->set_parent(this);
} else {
obj_ = cache_.back();
obj_->set_parent(this);
cache_.pop_back();
obj_->set_parent(this);
}
return data;
@ -457,8 +458,8 @@ redis_object& redis_object::create_child() {
objs_.emplace_back(obj);
} else {
obj = cache_.back();
cache_.pop_back();
obj->set_parent(this);
cache_.pop_back();
objs_.emplace_back(obj);
}