Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e4cc44cf80 | ||
![]() |
5e891d67a7 | ||
![]() |
c99c33e2e9 | ||
![]() |
71fcbd8bc5 |
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -97,4 +97,5 @@ namespace a8
|
||||
void ClearSendQueue(a8::SendQueueNode* node);
|
||||
|
||||
void Abort();
|
||||
void TestSleep(int count, int interval, const std::string text);
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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_) {
|
||||
|
@ -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_--;
|
||||
|
Loading…
x
Reference in New Issue
Block a user