Skip to content

Commit

Permalink
RTC: Support object cache pool. 4.0.75
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 27, 2021
1 parent 36f5524 commit 14bfc98
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ For previous versions, please read:

## V4 changes

* v4.0, 2021-02-27, RTC: Support object cache pool. 4.0.75
* v4.0, 2021-02-12, RTC: Support high performance timer about 25ms resolution. 4.0.72
* v4.0, 2021-02-10, RTC: Refine performance about 700+ streams. 4.0.71
* v4.0, 2021-02-08, RTC: Print stat for pli and timer every 5s. 4.0.70
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION4_HPP
#define SRS_CORE_VERSION4_HPP

#define SRS_VERSION4_REVISION 74
#define SRS_VERSION4_REVISION 75

#endif

2 comments on commit 14bfc98

@winlinvip
Copy link
Member Author

@winlinvip winlinvip commented on 14bfc98 Feb 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RTC有非常多的RTP包,由于对于实时性要求很高,所以每个Player每个时刻能处理的包却并不能太多(也就是服务器不能做延迟批量处理包)。
而直播很不一样,直播服务器可以主动缓存几百毫秒甚至秒级别的数据,批量处理和发送,以获得更高的性能。

因此,RTC对于对象的缓存就很重要,不断的new和delete对象,会导致性能低下。

首先,我们要将RTP Packet的缓存区分配,改成对象自己管理:

  • 改进代码,避免外部分配内存:ccb24a18bdf71b
  • RTP Packet自己管理内存:2ae7e2258d71c2
  • 将RTP Packet的底层缓冲区,改成1500字节大小,这样不同对象分配的内存块可以复用:d7f4de6

然后,我们使用对象池分配内存和对象:

  • 使用池分配RTP Packet和共享的Shared Message: 1833780
  • 不直接new对象,而是由池分配和回收:439a7fa
  • RTP Packet和Shared Message应该由不同的池分配,他们生命周期不同:d5b210a
  • 将RTP Packet的Payload,也改成由池管理:bffe9c5

关于对象池的性能优化:

其他重要说明:

  • 完善的统计信息,验证多少对象是new的,多少是由对象池分配的:e79293a
  • 只缓存1500字节的RTC UDP的包,因为只有RTC在消耗包,如果所有的Shared Message都回收到池中,在RTMP转RTC时池会不断变大:30809ae
  • 限制对象池的大小,按照MB估算,超过后丢包:7b3b738a29d6cb
  • 支持Reload对象池的开关和配置,可以动态观察池的作用:36f5524

@winlinvip
Copy link
Member Author

@winlinvip winlinvip commented on 14bfc98 May 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object Cache Pool,压测发现作用有限,已经从4.0的代码删除:f7b3225

代码保留在:feature/object_cache_pool

数据请看如下两个图对比:

  • 从感受来说,开启Cache后卡顿更多,在最卡的之前也会有卡;而关闭Cache后,前面一段没有卡顿。
  • CPU分布看,开启Cache后用户空间占用更多,关闭后内核空间更多,说明用户空间的效率提升了。
  • 发送的包数目是差不多的,带宽趋势差不多,关闭Cache后,用户空间函数更低,比如SrsRtpPacket2::encode等。

开启Cache

image

关闭Cache

image

Please sign in to comment.