state-threads
state-threads copied to clipboard
Lightweight thread library for C/C++ coroutine (similar to goroutine), for high performance network servers.
Now risc-v is more and more popular. Support risc-v is very easy. my code take some example from libc https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/riscv/swapcontext.S;h=53480a085c3418b5ba84ba115785f40f3c19ad89;hb=HEAD If have glic and glibc version is bigger than 2.0,...
参考:https://github.com/ossrs/srs/issues/307#issuecomment-615884074 目前内核最热的函数是`copy_user_enhanced_fast_string`,它主要是将用户空间的数据,拷贝到内核,可以想到是因为要将发送的UDP的payload拷贝到内核发送。 同样的,TCP也是这个是瓶颈,实际上Linux内核支持了很多种零拷贝方式,比如sendfile、splice、tee还有[MSG_ZEROCOPY](https://www.kernel.org/doc/html/latest/networking/msg_zerocopy.html)。 它提到是有代价的,如果要发送大量的数据,那么比较值得: ``` Copy avoidance is not a free lunch. As implemented, with page pinning, it replaces per byte copy cost with page accounting and completion notification overhead....
For WebRTC or UDP transport system, multiple threads or CPUs is essential important, please read https://github.com/ossrs/srs/issues/2188 The first step, is to simplify the state-threads. We should remove the dead code...
目前我在做的是将srs及libst源码放入android源码中交叉编译,然后集成进安卓手机中(手机CPU架构aarch64)。 android源码现在是用clang 编译。 在编译libst时,这个MD_GET_SP宏报错 ``` #elif defined(__aarch64__) /* https://github.com/ossrs/state-threads/issues/9 */ #define MD_STACK_GROWS_DOWN #define MD_USE_BUILTIN_SETJMP #define MD_GET_SP(_t) ((_t)->context[0].__jmpbuf[13]) ``` 报错内容: ``` system/core/libst/sched.c:616:9: error: member reference base type 'long' is not a...
I came across a performance issue in epoll mode, when there were thousands concurrent connections. Profiling shows that _st_epoll_dispatch() consumed a lot of CPU. After reviewing the function, I think...
See https://github.com/ossrs/srs/issues/307#issuecomment-612953502 Linux GSO,可以将多个UDP包延迟分包,提升性能,参考[UDP GSO原理及应用](https://blog.csdn.net/Wanli_Xing/article/details/102893871)。 > 注意:Linux 4.18.0及以上的内核才支持GSO,SRS会自动检测内核版本,下面是在开启GSO后的包,从抓包上看和不开启GSO一样的。如下抓包所示。 [rtc-plaintext-linux4-gso-ok.pcapng.zip](https://github.com/ossrs/srs/files/4473447/rtc-plaintext-linux4-gso-ok.pcapng.zip) [rtc-plaintext-multiple-slices-as-one-NALU.pcapng.zip](https://github.com/ossrs/srs/files/4473448/rtc-plaintext-multiple-slices-as-one-NALU.pcapng.zip) > 注意:如果强制在低版本内核上开启GSO,会有未知行为,如下抓包所示。 [rtc-plaintext-linux3-gso-invalid.pcapng.zip](https://github.com/ossrs/srs/files/4473445/rtc-plaintext-linux3-gso-invalid.pcapng.zip) SRS新增了包性能分析的API:http://localhost:1985/api/v1/perf 可以使用工具来分析:`./scripts/perf_gso.py http://localhost:1985/api/v1/perf` ## No GSO, Fragment at Source 不开启GSO,在接收包(Source)时将消息分成RTP包,统计数据如下:  > Note: 可以看到RTP的包数目比RTMP多了1.6倍,如果每个包都要内核处理,性能会有较大影响。 ## No GSO,...
We plan to replace it progressively by C++ 98 code and switch to MIT license. ## [Summary](#summary) 关于ST,我计划一点点换成C++ 98/MIT的,它目前有几个痛点: 1. 不维护了,最初的作者们估计都退休了,很多新的CPU和系统无法支持,这也是srs分支做了很多修改的原因。 2. 协议是MPL,其实是Mozilla的协议,Firefox也是这个协议,和LGPL类似,是OSI的标准协议,但这个用的少,不知道有什么坑没有。 3. 那些宏很奇怪,都是操作结构体的,之前展示过,应该换成C++ 98的,和C没什么差别,只是基本封装。C++也可以继续暴露C的API。 其实本身ST的LICENSE就是分多部分授权的: 1. ST的库是MPL授权。 2....