Comments (6)
void CTimer::_AddTimer(uint32_t interval, const base::CMemSharePtr& t, uint64_t& id) {
_time.Now();
uint64_t nowtime = _time.GetMsec();
uint64_t key = nowtime + interval;
std::unique_lock<std::recursive_mutex> lock(_mutex);
while (_timer_map.count(key)) {
key++;
}
_timer_map[key] = t;
id = key;
}
请问这边这个是采用时间轮的吗,如果定时任务很多,那么内存占用会不会特别大呢,尤其是这边以ms作为刻度?
from cppnet.
这个不是时间轮。这个定时器实现的比较粗糙,底层的结构用的是std::map的红黑树,key存储的是超时时的时间戳,如果定时器key冲突,则将key++,这样会造成一些时间上的偏差。
第二个问题,定时任务很多,那么内存占用会不会特别大呢?这里每添加一个定时器只会在红黑树内加一个智能指针和key的节点,内存增长应该也还在接受范围内。
当初在设计的时候考虑TCP网络库并不需要特别多的定时器任务,所以刻度上比较粗,当然应用层也很难获取精确的时间粒度。在HUDP库的定时器实现上,因为消息定时重传,定时器会比较多,在定时器实现上将相同key的定时器放到了链表里。其实这两种方式类似解决hash冲突的方式。
from cppnet.
非常感谢您的耐心解答!!!!😁
from cppnet.
用example写了一个简单的计算服务,http请求,当返回数据量较大时,下一次请求服务端会没有响应,客户端取消请求后,在下下次又可以收到客户端请求。这个是哪里出现的问题
from cppnet.
用example写了一个简单的计算服务,http请求,当返回数据量较大时,下一次请求服务端会没有响应,客户端取消请求后,在下下次又可以收到客户端请求。这个是哪里出现的问题
光听描述好像定位不出来问题,你方便加下微信吗,或者你fork下然后把你异常的代码上传一下,我看下代码
from cppnet.
用示例写了一个简单的计算服务,http请求,当返回数据量较大时,下一次请求服务端会没有响应,客户端取消请求后,在下下次又可以收到客户端请求。这个是哪里出现的问题
光听描述好像定位不出来问题,你方便加下微信吗,或者你叉下然后把你异常的代码上传一下,我看下代码
我微信号 Wj2976436572
from cppnet.
Related Issues (18)
- 最新vs2017下编译不通过 HOT 1
- ubuntu16环境下编译测试,同样用simple测试程序,客户端无法连接到服务端。 HOT 1
- How to add openssl support? HOT 2
- 感谢作者我跑通了
- 请问这个库考虑使用C++17重构吗? HOT 1
- simple下client的close无法被server捕捉到 HOT 2
- 请问该如何处理这个 EPOLLHUP 事件? HOT 1
- 作为客户端建立连接问题 HOT 1
- httpser: segmentation fault 以及 free(): corrupted unsorted chunks 错误 HOT 1
- Linux编译报错,存在两处函数未正确引用 HOT 2
- 内存分配PoolAlloter HOT 3
- 粘包问题 HOT 1
- 大数据包的问题 HOT 2
- simple test error HOT 3
- isn't type of port uint16_t? HOT 1
- windows环境下simple测试程序,client不能连接server HOT 2
- 基于上次做的更新,我在windows端再次做了测试,发现simpleServer获取对端IP地址异常。 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppnet.