通过减少线程切换提高服务器性能

This commit is contained in:
xiongziliang
2019-03-21 22:28:12 +08:00
parent 6238f5aa58
commit b78c14a2a3
9 changed files with 33 additions and 65 deletions

View File

@@ -232,7 +232,7 @@ inline bool HttpSession::checkLiveFlvStream(){
(*this) << SocketFlags(kSockFlags);
try{
start(mediaSrc);
start(getPoller(),mediaSrc);
}catch (std::exception &ex){
//该rtmp源不存在
shutdown();
@@ -683,36 +683,21 @@ inline void HttpSession::sendNotFound(bool bClose) {
void HttpSession::onWrite(const Buffer::Ptr &buffer) {
weak_ptr<HttpSession> weakSelf = dynamic_pointer_cast<HttpSession>(shared_from_this());
async([weakSelf,buffer](){
auto strongSelf = weakSelf.lock();
if(!strongSelf) {
return;
}
strongSelf->_ticker.resetTime();
strongSelf->_ui64TotalBytes += buffer->size();
strongSelf->send(buffer);
});
_ticker.resetTime();
_ui64TotalBytes += buffer->size();
send(buffer);
}
void HttpSession::onWrite(const char *data, int len) {
BufferRaw::Ptr buffer(new BufferRaw);
buffer->assign(data,len);
weak_ptr<HttpSession> weakSelf = dynamic_pointer_cast<HttpSession>(shared_from_this());
async([weakSelf,buffer](){
auto strongSelf = weakSelf.lock();
if(!strongSelf) {
return;
}
strongSelf->_ticker.resetTime();
strongSelf->_ui64TotalBytes += buffer->size();
strongSelf->send(buffer);
});
_ticker.resetTime();
_ui64TotalBytes += buffer->size();
send(buffer);
}
void HttpSession::onDetach() {
safeShutdown();
shutdown();
}
std::shared_ptr<FlvMuxer> HttpSession::getSharedPtr(){