Compare commits

...

4 Commits

Author SHA1 Message Date
aozhiwei
e4cc44cf80 1 2024-09-27 10:49:06 +08:00
aozhiwei
5e891d67a7 1 2024-09-26 15:53:03 +08:00
aozhiwei
c99c33e2e9 1 2024-09-26 15:11:16 +08:00
aozhiwei
71fcbd8bc5 1 2024-09-26 15:09:12 +08:00
7 changed files with 102 additions and 2 deletions

View File

@ -1,6 +1,8 @@
#include <a8/a8.h>
#include <a8/perfmonitor.h>
#include <mutex>
namespace a8
{
@ -10,10 +12,60 @@ namespace a8
void PerfMonitor::Init()
{
mutex_ = std::make_shared<std::mutex>();
}
void PerfMonitor::UnInit()
{
}
long long PerfMonitor::AddV(const std::string key, long long val)
{
long long result = 0;
mutex_->lock();
auto itr = dyn_hash_.find(key);
if (itr == dyn_hash_.end()) {
dyn_hash_[key] = val;
result = val;
} else {
itr->second = itr->second + val;
result = itr->second;
}
mutex_->unlock();
return result;
}
long long PerfMonitor::SubV(const std::string key, long long val)
{
return AddV(key, -val);
}
void PerfMonitor::SetV(const std::string key, long long val)
{
mutex_->lock();
dyn_hash_[key] = val;
mutex_->unlock();
}
long long PerfMonitor::GetV(const std::string key)
{
long long result = 0;
mutex_->lock();
auto itr = dyn_hash_.find(key);
if (itr != dyn_hash_.end()) {
result = itr->second;
}
mutex_->unlock();
return result;
}
void PerfMonitor::Dump()
{
mutex_->lock();
for (auto& pair : dyn_hash_) {
a8::XPrintf("Perfmonitor::V %s = %d\n", {pair.first, pair.second});
}
mutex_->unlock();
}
}

View File

@ -15,12 +15,21 @@ namespace a8
void Init();
void UnInit();
long long AddV(const std::string key, long long val);
long long SubV(const std::string key, long long val);
void SetV(const std::string key, long long val);
long long GetV(const std::string key);
void Dump();
public:
long long send_eagain_times = 0;
long long recv_eagain_times = 0;
long long max_send_time = 0;
long long max_recv_time = 0;
private:
std::shared_ptr<std::mutex> mutex_;
std::map<std::string, long long> dyn_hash_;
};
}

View File

@ -342,4 +342,13 @@ namespace a8
abort();
}
void TestSleep(int count, int interval, const std::string text)
{
int i = 0;
while (i++ < count) {
sleep(interval);
}
XPrintf("TestSleep %s\n", {text});
}
}

View File

@ -97,4 +97,5 @@ namespace a8
void ClearSendQueue(a8::SendQueueNode* node);
void Abort();
void TestSleep(int count, int interval, const std::string text);
}

View File

@ -12,6 +12,7 @@
#include <netinet/tcp.h>
#include <a8/a8.h>
#include <a8/perfmonitor.h>
#include <a8/tcpclient.h>
const int MAX_RECV_BUFFERSIZE = 1024 * 64;
@ -80,6 +81,9 @@ namespace a8
}
send_buffer_mutex_->unlock();
NotifySendCond();
#ifdef MMCHK
a8::PerfMonitor::Instance()->AddV("a8.TcpClient.count", 1);
#endif
}
}
@ -228,6 +232,9 @@ namespace a8
worknode = worknode->next;
free(currnode->buff);
free(currnode);
#ifdef MMCHK
a8::PerfMonitor::Instance()->SubV("a8.TcpClient.count", 1);
#endif
}
}
@ -241,6 +248,9 @@ namespace a8
worknode = worknode->next;
free(currnode->buff);
free(currnode);
#ifdef MMCHK
a8::PerfMonitor::Instance()->SubV("a8.TcpClient.count", 1);
#endif
}
}

View File

@ -24,10 +24,16 @@ namespace a8
{
INIT_LIST_HEAD(&session_entry);
max_packet_len_ = DEFAULT_MAX_PACKET_LEN;
#ifdef MMCHK
a8::PerfMonitor::Instance()->AddV("a8.TcpSession.count", 1);
#endif
}
TcpSession::~TcpSession()
{
#ifdef MMCHK
a8::PerfMonitor::Instance()->SubV("a8.TcpSession.count", 1);
#endif
}
void TcpSession::SetMaxPacketLen(int max_packet_len)
@ -86,6 +92,9 @@ namespace a8
}
send_buffer_mutex_.unlock();
++master->send_node_num;
#ifdef MMCHK
a8::PerfMonitor::Instance()->AddV("a8.TcpSession.sendBuf", 1);
#endif
}
}
@ -266,6 +275,9 @@ namespace a8
}
free(pdelnode);
--master->send_node_num;
#ifdef MMCHK
a8::PerfMonitor::Instance()->SubV("a8.TcpSession.sendBuf", 1);
#endif
}
}
@ -279,6 +291,9 @@ namespace a8
}
free(pdelnode);
--master->send_node_num;
#ifdef MMCHK
a8::PerfMonitor::Instance()->SubV("a8.TcpSession.sendBuf", 1);
#endif
}
}
@ -303,6 +318,9 @@ namespace a8
a8::SendQueueNode *pdelnode = work_node_;
work_node_ = work_node_->next;
--master->send_node_num;
#ifdef MMCHK
a8::PerfMonitor::Instance()->SubV("a8.TcpSession.sendBuf", 1);
#endif
++master->sent_node_num;
master->sent_bytes_num += pdelnode->sent_bytes;
if (!work_node_) {

View File

@ -51,7 +51,7 @@ namespace a8
ClearTimeOutSocket();
a8::TcpSession* p = nullptr;
if (top_node_) {
if (time(nullptr) - top_node_->addtime >= 30) {
if (time(nullptr) - top_node_->addtime >= 20) {
p = top_node_->session;
a8::TcpSessionPool::TcpSessionNode* pdelnode = top_node_;
top_node_ = top_node_->next;
@ -68,12 +68,13 @@ namespace a8
void TcpSessionPool::ClearTimeOutSocket()
{
while (top_node_) {
if(time(nullptr) - top_node_->addtime > 60 * 5){
if(time(nullptr) - top_node_->addtime > 30){
a8::TcpSessionPool::TcpSessionNode* pdelnode = top_node_;
top_node_ = top_node_->next;
if (!top_node_) {
bot_node_ = NULL;
}
pdelnode->session->Destory();
delete pdelnode->session;
delete pdelnode;
count_--;