add performance header to control options for performance. 2.0.50
正在显示
15 个修改的文件
包含
167 行增加
和
25 行删除
| @@ -355,7 +355,7 @@ if [ $SRS_MIPS_UBUNTU12 = YES ]; then SrsLinkOptions="${SrsLinkOptions} -lgcc_eh | @@ -355,7 +355,7 @@ if [ $SRS_MIPS_UBUNTU12 = YES ]; then SrsLinkOptions="${SrsLinkOptions} -lgcc_eh | ||
| 355 | MODULE_ID="CORE" | 355 | MODULE_ID="CORE" |
| 356 | MODULE_DEPENDS=() | 356 | MODULE_DEPENDS=() |
| 357 | ModuleLibIncs=(${SRS_OBJS_DIR}) | 357 | ModuleLibIncs=(${SRS_OBJS_DIR}) |
| 358 | -MODULE_FILES=("srs_core" "srs_core_autofree") | 358 | +MODULE_FILES=("srs_core" "srs_core_autofree" "srs_core_performance") |
| 359 | CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh | 359 | CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh |
| 360 | CORE_OBJS="${MODULE_OBJS[@]}" | 360 | CORE_OBJS="${MODULE_OBJS[@]}" |
| 361 | # | 361 | # |
| @@ -28,6 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -28,6 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 28 | #include <srs_app_rtmp_conn.hpp> | 28 | #include <srs_app_rtmp_conn.hpp> |
| 29 | #include <srs_protocol_buffer.hpp> | 29 | #include <srs_protocol_buffer.hpp> |
| 30 | #include <srs_kernel_utility.hpp> | 30 | #include <srs_kernel_utility.hpp> |
| 31 | +#include <srs_core_performance.hpp> | ||
| 31 | 32 | ||
| 32 | // when we read from socket less than this value, | 33 | // when we read from socket less than this value, |
| 33 | // sleep a while to merge read. | 34 | // sleep a while to merge read. |
| @@ -299,6 +300,7 @@ void SrsPublishRecvThread::on_thread_start() | @@ -299,6 +300,7 @@ void SrsPublishRecvThread::on_thread_start() | ||
| 299 | // we donot set the auto response to false, | 300 | // we donot set the auto response to false, |
| 300 | // for the main thread never send message. | 301 | // for the main thread never send message. |
| 301 | 302 | ||
| 303 | +#ifdef SRS_PERF_MERGED_READ | ||
| 302 | // socket recv buffer, system will double it. | 304 | // socket recv buffer, system will double it. |
| 303 | int nb_rbuf = SRS_MR_SOCKET_BUFFER / 2; | 305 | int nb_rbuf = SRS_MR_SOCKET_BUFFER / 2; |
| 304 | socklen_t sock_buf_size = sizeof(int); | 306 | socklen_t sock_buf_size = sizeof(int); |
| @@ -312,6 +314,7 @@ void SrsPublishRecvThread::on_thread_start() | @@ -312,6 +314,7 @@ void SrsPublishRecvThread::on_thread_start() | ||
| 312 | // enable the merge read | 314 | // enable the merge read |
| 313 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 315 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 314 | rtmp->set_merge_read(true, nb_rbuf, this); | 316 | rtmp->set_merge_read(true, nb_rbuf, this); |
| 317 | +#endif | ||
| 315 | } | 318 | } |
| 316 | 319 | ||
| 317 | void SrsPublishRecvThread::on_thread_stop() | 320 | void SrsPublishRecvThread::on_thread_stop() |
| @@ -323,9 +326,11 @@ void SrsPublishRecvThread::on_thread_stop() | @@ -323,9 +326,11 @@ void SrsPublishRecvThread::on_thread_stop() | ||
| 323 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/244 | 326 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/244 |
| 324 | st_cond_signal(error); | 327 | st_cond_signal(error); |
| 325 | 328 | ||
| 329 | +#ifdef SRS_PERF_MERGED_READ | ||
| 326 | // disable the merge read | 330 | // disable the merge read |
| 327 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 331 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 328 | rtmp->set_merge_read(false, 0, NULL); | 332 | rtmp->set_merge_read(false, 0, NULL); |
| 333 | +#endif | ||
| 329 | } | 334 | } |
| 330 | 335 | ||
| 331 | bool SrsPublishRecvThread::can_handle() | 336 | bool SrsPublishRecvThread::can_handle() |
| @@ -359,6 +364,7 @@ void SrsPublishRecvThread::on_recv_error(int ret) | @@ -359,6 +364,7 @@ void SrsPublishRecvThread::on_recv_error(int ret) | ||
| 359 | st_cond_signal(error); | 364 | st_cond_signal(error); |
| 360 | } | 365 | } |
| 361 | 366 | ||
| 367 | +#ifdef SRS_PERF_MERGED_READ | ||
| 362 | void SrsPublishRecvThread::on_read(ssize_t nread) | 368 | void SrsPublishRecvThread::on_read(ssize_t nread) |
| 363 | { | 369 | { |
| 364 | if (nread < 0 || mr_sleep_ms <= 0) { | 370 | if (nread < 0 || mr_sleep_ms <= 0) { |
| @@ -378,6 +384,8 @@ void SrsPublishRecvThread::on_read(ssize_t nread) | @@ -378,6 +384,8 @@ void SrsPublishRecvThread::on_read(ssize_t nread) | ||
| 378 | 384 | ||
| 379 | void SrsPublishRecvThread::on_buffer_change(int nb_buffer) | 385 | void SrsPublishRecvThread::on_buffer_change(int nb_buffer) |
| 380 | { | 386 | { |
| 387 | + srs_assert(nb_buffer > 0); | ||
| 388 | + | ||
| 381 | // set percent. | 389 | // set percent. |
| 382 | mr_small_bytes = (int)(nb_buffer / SRS_MR_SMALL_PERCENT); | 390 | mr_small_bytes = (int)(nb_buffer / SRS_MR_SMALL_PERCENT); |
| 383 | // select the smaller | 391 | // select the smaller |
| @@ -399,3 +407,4 @@ void SrsPublishRecvThread::on_buffer_change(int nb_buffer) | @@ -399,3 +407,4 @@ void SrsPublishRecvThread::on_buffer_change(int nb_buffer) | ||
| 399 | 407 | ||
| 400 | srs_trace("merged read, buffer=%d, small=%d, sleep=%d", nb_buffer, mr_small_bytes, mr_sleep_ms); | 408 | srs_trace("merged read, buffer=%d, small=%d, sleep=%d", nb_buffer, mr_small_bytes, mr_sleep_ms); |
| 401 | } | 409 | } |
| 410 | +#endif |
| @@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 34 | 34 | ||
| 35 | #include <srs_app_thread.hpp> | 35 | #include <srs_app_thread.hpp> |
| 36 | #include <srs_protocol_buffer.hpp> | 36 | #include <srs_protocol_buffer.hpp> |
| 37 | +#include <srs_core_performance.hpp> | ||
| 37 | 38 | ||
| 38 | class SrsRtmpServer; | 39 | class SrsRtmpServer; |
| 39 | class SrsMessage; | 40 | class SrsMessage; |
| @@ -133,7 +134,10 @@ public: | @@ -133,7 +134,10 @@ public: | ||
| 133 | * the publish recv thread got message and callback the source method to process message. | 134 | * the publish recv thread got message and callback the source method to process message. |
| 134 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/237 | 135 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/237 |
| 135 | */ | 136 | */ |
| 136 | -class SrsPublishRecvThread : virtual public ISrsMessageHandler, virtual public IMergeReadHandler | 137 | +class SrsPublishRecvThread : virtual public ISrsMessageHandler |
| 138 | +#ifdef SRS_PERF_MERGED_READ | ||
| 139 | + , virtual public IMergeReadHandler | ||
| 140 | +#endif | ||
| 137 | { | 141 | { |
| 138 | private: | 142 | private: |
| 139 | SrsRecvThread trd; | 143 | SrsRecvThread trd; |
| @@ -178,8 +182,10 @@ public: | @@ -178,8 +182,10 @@ public: | ||
| 178 | virtual void on_recv_error(int ret); | 182 | virtual void on_recv_error(int ret); |
| 179 | // interface IMergeReadHandler | 183 | // interface IMergeReadHandler |
| 180 | public: | 184 | public: |
| 185 | +#ifdef SRS_PERF_MERGED_READ | ||
| 181 | virtual void on_read(ssize_t nread); | 186 | virtual void on_read(ssize_t nread); |
| 182 | virtual void on_buffer_change(int nb_buffer); | 187 | virtual void on_buffer_change(int nb_buffer); |
| 188 | +#endif | ||
| 183 | }; | 189 | }; |
| 184 | 190 | ||
| 185 | #endif | 191 | #endif |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 49 | 34 | +#define VERSION_REVISION 50 |
| 35 | // server info. | 35 | // server info. |
| 36 | #define RTMP_SIG_SRS_KEY "SRS" | 36 | #define RTMP_SIG_SRS_KEY "SRS" |
| 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" | 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" |
trunk/src/core/srs_core_performance.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <srs_core_performance.hpp> | ||
| 25 | + |
trunk/src/core/srs_core_performance.hpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_CORE_PERFORMANCE_HPP | ||
| 25 | +#define SRS_CORE_PERFORMANCE_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_core_performance.hpp> | ||
| 29 | +*/ | ||
| 30 | + | ||
| 31 | +#include <srs_core.hpp> | ||
| 32 | + | ||
| 33 | +/** | ||
| 34 | +* this file defines the perfromance options. | ||
| 35 | +*/ | ||
| 36 | + | ||
| 37 | +/** | ||
| 38 | +* to improve read performance, merge some packets then read, | ||
| 39 | +* when it on and read small bytes, we sleep to wait more data., | ||
| 40 | +* that is, we merge some data to read together. | ||
| 41 | +* @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | ||
| 42 | +* @remark other macros: | ||
| 43 | +* SOCKET_MAX_BUF, the max size of user-space buffer. | ||
| 44 | +* SOCKET_READ_SIZE, the user space buffer for socket. | ||
| 45 | +* SRS_MR_MAX_BITRATE_KBPS, the kbps of stream for system to guess the sleep time. | ||
| 46 | +* SRS_MR_AVERAGE_BITRATE_KBPS, the average kbps of system. | ||
| 47 | +* SRS_MR_MIN_BITRATE_KBPS, the min kbps of system. | ||
| 48 | +* SRS_MR_MAX_SLEEP_MS, the max sleep time, the latency+ when sleep+. | ||
| 49 | +* SRS_MR_SMALL_BYTES, sleep when got small bytes, the latency+ when small+. | ||
| 50 | +* SRS_MR_SMALL_PERCENT, to calc the small bytes = SRS_MR_SOCKET_BUFFER/percent. | ||
| 51 | +* SRS_MR_SOCKET_BUFFER, the socket buffer to set fd. | ||
| 52 | +* @remark the actual socket buffer used to set the buffer user-space size. | ||
| 53 | +* buffer = min(SOCKET_MAX_BUF, SRS_MR_SOCKET_BUFFER, SOCKET_READ_SIZE) | ||
| 54 | +* small bytes = max(buffer/SRS_MR_SMALL_PERCENT, SRS_MR_SMALL_BYTES) | ||
| 55 | +* sleep = calc the sleep by kbps and buffer. | ||
| 56 | +* @remark the main merged-read algorithm: | ||
| 57 | +* while true: | ||
| 58 | +* nread = read from socket. | ||
| 59 | +* sleep if nread < small bytes | ||
| 60 | +* process bytes. | ||
| 61 | +* @example, for the default settings, this algorithm will use: | ||
| 62 | +* socket buffer set to 64KB, | ||
| 63 | +* user space buffer set to 64KB, | ||
| 64 | +* buffer=65536B, small=4096B, sleep=780ms | ||
| 65 | +* that is, when got nread bytes smaller than 4KB, sleep(780ms). | ||
| 66 | +*/ | ||
| 67 | +#define SRS_PERF_MERGED_READ | ||
| 68 | +#undef SRS_PERF_MERGED_READ | ||
| 69 | + | ||
| 70 | +#endif | ||
| 71 | + |
| @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 26 | #include <srs_kernel_error.hpp> | 26 | #include <srs_kernel_error.hpp> |
| 27 | #include <srs_kernel_log.hpp> | 27 | #include <srs_kernel_log.hpp> |
| 28 | #include <srs_kernel_utility.hpp> | 28 | #include <srs_kernel_utility.hpp> |
| 29 | +#include <srs_core_performance.hpp> | ||
| 29 | 30 | ||
| 30 | // the max header size, | 31 | // the max header size, |
| 31 | // @see SrsProtocol::read_message_header(). | 32 | // @see SrsProtocol::read_message_header(). |
| @@ -72,6 +73,7 @@ void SrsSimpleBuffer::append(const char* bytes, int size) | @@ -72,6 +73,7 @@ void SrsSimpleBuffer::append(const char* bytes, int size) | ||
| 72 | data.insert(data.end(), bytes, bytes + size); | 73 | data.insert(data.end(), bytes, bytes + size); |
| 73 | } | 74 | } |
| 74 | 75 | ||
| 76 | +#ifdef SRS_PERF_MERGED_READ | ||
| 75 | IMergeReadHandler::IMergeReadHandler() | 77 | IMergeReadHandler::IMergeReadHandler() |
| 76 | { | 78 | { |
| 77 | } | 79 | } |
| @@ -79,11 +81,14 @@ IMergeReadHandler::IMergeReadHandler() | @@ -79,11 +81,14 @@ IMergeReadHandler::IMergeReadHandler() | ||
| 79 | IMergeReadHandler::~IMergeReadHandler() | 81 | IMergeReadHandler::~IMergeReadHandler() |
| 80 | { | 82 | { |
| 81 | } | 83 | } |
| 84 | +#endif | ||
| 82 | 85 | ||
| 83 | SrsFastBuffer::SrsFastBuffer() | 86 | SrsFastBuffer::SrsFastBuffer() |
| 84 | { | 87 | { |
| 88 | +#ifdef SRS_PERF_MERGED_READ | ||
| 85 | merged_read = false; | 89 | merged_read = false; |
| 86 | _handler = NULL; | 90 | _handler = NULL; |
| 91 | +#endif | ||
| 87 | 92 | ||
| 88 | p = end = buffer = NULL; | 93 | p = end = buffer = NULL; |
| 89 | nb_buffer = 0; | 94 | nb_buffer = 0; |
| @@ -160,6 +165,7 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) | @@ -160,6 +165,7 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) | ||
| 160 | return ret; | 165 | return ret; |
| 161 | } | 166 | } |
| 162 | 167 | ||
| 168 | +#ifdef SRS_PERF_MERGED_READ | ||
| 163 | /** | 169 | /** |
| 164 | * to improve read performance, merge some packets then read, | 170 | * to improve read performance, merge some packets then read, |
| 165 | * when it on and read small bytes, we sleep to wait more data., | 171 | * when it on and read small bytes, we sleep to wait more data., |
| @@ -169,6 +175,7 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) | @@ -169,6 +175,7 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) | ||
| 169 | if (merged_read && _handler) { | 175 | if (merged_read && _handler) { |
| 170 | _handler->on_read(nread); | 176 | _handler->on_read(nread); |
| 171 | } | 177 | } |
| 178 | +#endif | ||
| 172 | 179 | ||
| 173 | // we just move the ptr to next. | 180 | // we just move the ptr to next. |
| 174 | srs_assert((int)nread > 0); | 181 | srs_assert((int)nread > 0); |
| @@ -178,6 +185,7 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) | @@ -178,6 +185,7 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) | ||
| 178 | return ret; | 185 | return ret; |
| 179 | } | 186 | } |
| 180 | 187 | ||
| 188 | +#ifdef SRS_PERF_MERGED_READ | ||
| 181 | void SrsFastBuffer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) | 189 | void SrsFastBuffer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) |
| 182 | { | 190 | { |
| 183 | merged_read = v; | 191 | merged_read = v; |
| @@ -194,6 +202,7 @@ void SrsFastBuffer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* ha | @@ -194,6 +202,7 @@ void SrsFastBuffer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* ha | ||
| 194 | _handler->on_buffer_change(nb_buffer); | 202 | _handler->on_buffer_change(nb_buffer); |
| 195 | } | 203 | } |
| 196 | } | 204 | } |
| 205 | +#endif | ||
| 197 | 206 | ||
| 198 | void SrsFastBuffer::on_chunk_size(int32_t chunk_size) | 207 | void SrsFastBuffer::on_chunk_size(int32_t chunk_size) |
| 199 | { | 208 | { |
| @@ -208,9 +217,11 @@ void SrsFastBuffer::on_chunk_size(int32_t chunk_size) | @@ -208,9 +217,11 @@ void SrsFastBuffer::on_chunk_size(int32_t chunk_size) | ||
| 208 | reset_buffer(buffer_size); | 217 | reset_buffer(buffer_size); |
| 209 | } | 218 | } |
| 210 | 219 | ||
| 220 | +#ifdef SRS_PERF_MERGED_READ | ||
| 211 | if (_handler) { | 221 | if (_handler) { |
| 212 | _handler->on_buffer_change(nb_buffer); | 222 | _handler->on_buffer_change(nb_buffer); |
| 213 | } | 223 | } |
| 224 | +#endif | ||
| 214 | } | 225 | } |
| 215 | 226 | ||
| 216 | int SrsFastBuffer::buffer_size() | 227 | int SrsFastBuffer::buffer_size() |
| @@ -33,6 +33,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,6 +33,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | #include <vector> | 33 | #include <vector> |
| 34 | 34 | ||
| 35 | #include <srs_protocol_io.hpp> | 35 | #include <srs_protocol_io.hpp> |
| 36 | +#include <srs_core_performance.hpp> | ||
| 37 | + | ||
| 38 | +// 4KB=4096 | ||
| 39 | +// 8KB=8192 | ||
| 40 | +// 16KB=16384 | ||
| 41 | +// 32KB=32768 | ||
| 42 | +// 64KB=65536 | ||
| 43 | +// @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | ||
| 44 | +#define SOCKET_READ_SIZE 65536 | ||
| 45 | +// the max buffer for user space socket buffer. | ||
| 46 | +#define SOCKET_MAX_BUF SOCKET_READ_SIZE | ||
| 36 | 47 | ||
| 37 | /** | 48 | /** |
| 38 | * the simple buffer use vector to append bytes, | 49 | * the simple buffer use vector to append bytes, |
| @@ -71,16 +82,7 @@ public: | @@ -71,16 +82,7 @@ public: | ||
| 71 | virtual void append(const char* bytes, int size); | 82 | virtual void append(const char* bytes, int size); |
| 72 | }; | 83 | }; |
| 73 | 84 | ||
| 74 | -// 4KB=4096 | ||
| 75 | -// 8KB=8192 | ||
| 76 | -// 16KB=16384 | ||
| 77 | -// 32KB=32768 | ||
| 78 | -// 64KB=65536 | ||
| 79 | -// @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | ||
| 80 | -#define SOCKET_READ_SIZE 65536 | ||
| 81 | -// the max buffer for user space socket buffer. | ||
| 82 | -#define SOCKET_MAX_BUF SOCKET_READ_SIZE | ||
| 83 | - | 85 | +#ifdef SRS_PERF_MERGED_READ |
| 84 | /** | 86 | /** |
| 85 | * to improve read performance, merge some packets then read, | 87 | * to improve read performance, merge some packets then read, |
| 86 | * when it on and read small bytes, we sleep to wait more data., | 88 | * when it on and read small bytes, we sleep to wait more data., |
| @@ -105,17 +107,21 @@ public: | @@ -105,17 +107,21 @@ public: | ||
| 105 | */ | 107 | */ |
| 106 | virtual void on_buffer_change(int nb_buffer) = 0; | 108 | virtual void on_buffer_change(int nb_buffer) = 0; |
| 107 | }; | 109 | }; |
| 110 | +#endif | ||
| 108 | 111 | ||
| 109 | /** | 112 | /** |
| 110 | * the buffer provices bytes cache for protocol. generally, | 113 | * the buffer provices bytes cache for protocol. generally, |
| 111 | * protocol recv data from socket, put into buffer, decode to RTMP message. | 114 | * protocol recv data from socket, put into buffer, decode to RTMP message. |
| 112 | */ | 115 | */ |
| 116 | +// TODO: FIXME: add utest for it. | ||
| 113 | class SrsFastBuffer | 117 | class SrsFastBuffer |
| 114 | { | 118 | { |
| 115 | private: | 119 | private: |
| 120 | +#ifdef SRS_PERF_MERGED_READ | ||
| 116 | // the merged handler | 121 | // the merged handler |
| 117 | bool merged_read; | 122 | bool merged_read; |
| 118 | IMergeReadHandler* _handler; | 123 | IMergeReadHandler* _handler; |
| 124 | +#endif | ||
| 119 | // the user-space buffer to fill by reader, | 125 | // the user-space buffer to fill by reader, |
| 120 | // which use fast index and reset when chunk body read ok. | 126 | // which use fast index and reset when chunk body read ok. |
| 121 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/248 | 127 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/248 |
| @@ -160,6 +166,7 @@ public: | @@ -160,6 +166,7 @@ public: | ||
| 160 | */ | 166 | */ |
| 161 | virtual int grow(ISrsBufferReader* reader, int required_size); | 167 | virtual int grow(ISrsBufferReader* reader, int required_size); |
| 162 | public: | 168 | public: |
| 169 | +#ifdef SRS_PERF_MERGED_READ | ||
| 163 | /** | 170 | /** |
| 164 | * to improve read performance, merge some packets then read, | 171 | * to improve read performance, merge some packets then read, |
| 165 | * when it on and read small bytes, we sleep to wait more data., | 172 | * when it on and read small bytes, we sleep to wait more data., |
| @@ -170,6 +177,8 @@ public: | @@ -170,6 +177,8 @@ public: | ||
| 170 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 177 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 171 | */ | 178 | */ |
| 172 | virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); | 179 | virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); |
| 180 | +#endif | ||
| 181 | +public: | ||
| 173 | /** | 182 | /** |
| 174 | * when chunk size changed, the buffer should change the buffer also. | 183 | * when chunk size changed, the buffer should change the buffer also. |
| 175 | * to keep the socket buffer size always greater than chunk size. | 184 | * to keep the socket buffer size always greater than chunk size. |
| @@ -745,10 +745,12 @@ void SrsRtmpServer::set_auto_response(bool v) | @@ -745,10 +745,12 @@ void SrsRtmpServer::set_auto_response(bool v) | ||
| 745 | protocol->set_auto_response(v); | 745 | protocol->set_auto_response(v); |
| 746 | } | 746 | } |
| 747 | 747 | ||
| 748 | +#ifdef SRS_PERF_MERGED_READ | ||
| 748 | void SrsRtmpServer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) | 749 | void SrsRtmpServer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) |
| 749 | { | 750 | { |
| 750 | protocol->set_merge_read(v, max_buffer, handler); | 751 | protocol->set_merge_read(v, max_buffer, handler); |
| 751 | } | 752 | } |
| 753 | +#endif | ||
| 752 | 754 | ||
| 753 | void SrsRtmpServer::set_recv_timeout(int64_t timeout_us) | 755 | void SrsRtmpServer::set_recv_timeout(int64_t timeout_us) |
| 754 | { | 756 | { |
| @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | #include <string> | 33 | #include <string> |
| 34 | 34 | ||
| 35 | #include <srs_protocol_stack.hpp> | 35 | #include <srs_protocol_stack.hpp> |
| 36 | +#include <srs_core_performance.hpp> | ||
| 36 | 37 | ||
| 37 | class SrsProtocol; | 38 | class SrsProtocol; |
| 38 | class ISrsProtocolReaderWriter; | 39 | class ISrsProtocolReaderWriter; |
| @@ -343,6 +344,7 @@ public: | @@ -343,6 +344,7 @@ public: | ||
| 343 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 | 344 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 |
| 344 | */ | 345 | */ |
| 345 | virtual void set_auto_response(bool v); | 346 | virtual void set_auto_response(bool v); |
| 347 | +#ifdef SRS_PERF_MERGED_READ | ||
| 346 | /** | 348 | /** |
| 347 | * to improve read performance, merge some packets then read, | 349 | * to improve read performance, merge some packets then read, |
| 348 | * when it on and read small bytes, we sleep to wait more data., | 350 | * when it on and read small bytes, we sleep to wait more data., |
| @@ -353,6 +355,7 @@ public: | @@ -353,6 +355,7 @@ public: | ||
| 353 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 355 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 354 | */ | 356 | */ |
| 355 | virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); | 357 | virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); |
| 358 | +#endif | ||
| 356 | /** | 359 | /** |
| 357 | * set/get the recv timeout in us. | 360 | * set/get the recv timeout in us. |
| 358 | * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. | 361 | * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. |
| @@ -479,10 +479,12 @@ int SrsProtocol::manual_response_flush() | @@ -479,10 +479,12 @@ int SrsProtocol::manual_response_flush() | ||
| 479 | return ret; | 479 | return ret; |
| 480 | } | 480 | } |
| 481 | 481 | ||
| 482 | +#ifdef SRS_PERF_MERGED_READ | ||
| 482 | void SrsProtocol::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) | 483 | void SrsProtocol::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) |
| 483 | { | 484 | { |
| 484 | in_buffer->set_merge_read(v, max_buffer, handler); | 485 | in_buffer->set_merge_read(v, max_buffer, handler); |
| 485 | } | 486 | } |
| 487 | +#endif | ||
| 486 | 488 | ||
| 487 | void SrsProtocol::set_recv_timeout(int64_t timeout_us) | 489 | void SrsProtocol::set_recv_timeout(int64_t timeout_us) |
| 488 | { | 490 | { |
| @@ -42,6 +42,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -42,6 +42,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 42 | #include <srs_kernel_log.hpp> | 42 | #include <srs_kernel_log.hpp> |
| 43 | #include <srs_kernel_error.hpp> | 43 | #include <srs_kernel_error.hpp> |
| 44 | #include <srs_kernel_consts.hpp> | 44 | #include <srs_kernel_consts.hpp> |
| 45 | +#include <srs_core_performance.hpp> | ||
| 45 | 46 | ||
| 46 | class ISrsProtocolReaderWriter; | 47 | class ISrsProtocolReaderWriter; |
| 47 | class SrsFastBuffer; | 48 | class SrsFastBuffer; |
| @@ -271,6 +272,7 @@ public: | @@ -271,6 +272,7 @@ public: | ||
| 271 | */ | 272 | */ |
| 272 | virtual int manual_response_flush(); | 273 | virtual int manual_response_flush(); |
| 273 | public: | 274 | public: |
| 275 | +#ifdef SRS_PERF_MERGED_READ | ||
| 274 | /** | 276 | /** |
| 275 | * to improve read performance, merge some packets then read, | 277 | * to improve read performance, merge some packets then read, |
| 276 | * when it on and read small bytes, we sleep to wait more data., | 278 | * when it on and read small bytes, we sleep to wait more data., |
| @@ -281,6 +283,7 @@ public: | @@ -281,6 +283,7 @@ public: | ||
| 281 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 283 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 282 | */ | 284 | */ |
| 283 | virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); | 285 | virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); |
| 286 | +#endif | ||
| 284 | public: | 287 | public: |
| 285 | /** | 288 | /** |
| 286 | * set/get the recv timeout in us. | 289 | * set/get the recv timeout in us. |
| @@ -15,6 +15,8 @@ file | @@ -15,6 +15,8 @@ file | ||
| 15 | ..\core\srs_core.cpp, | 15 | ..\core\srs_core.cpp, |
| 16 | ..\core\srs_core_autofree.hpp, | 16 | ..\core\srs_core_autofree.hpp, |
| 17 | ..\core\srs_core_autofree.cpp, | 17 | ..\core\srs_core_autofree.cpp, |
| 18 | + ..\core\srs_core_performance.hpp, | ||
| 19 | + ..\core\srs_core_performance.cpp, | ||
| 18 | kernel readonly separator, | 20 | kernel readonly separator, |
| 19 | ..\kernel\srs_kernel_codec.hpp, | 21 | ..\kernel\srs_kernel_codec.hpp, |
| 20 | ..\kernel\srs_kernel_codec.cpp, | 22 | ..\kernel\srs_kernel_codec.cpp, |
| @@ -203,7 +203,7 @@ int MockBufferReader::read(void* buf, size_t size, ssize_t* nread) | @@ -203,7 +203,7 @@ int MockBufferReader::read(void* buf, size_t size, ssize_t* nread) | ||
| 203 | 203 | ||
| 204 | VOID TEST(KernelBufferTest, DefaultObject) | 204 | VOID TEST(KernelBufferTest, DefaultObject) |
| 205 | { | 205 | { |
| 206 | - SrsFastBuffer b; | 206 | + SrsSimpleBuffer b; |
| 207 | 207 | ||
| 208 | EXPECT_EQ(0, b.length()); | 208 | EXPECT_EQ(0, b.length()); |
| 209 | EXPECT_EQ(NULL, b.bytes()); | 209 | EXPECT_EQ(NULL, b.bytes()); |
| @@ -211,7 +211,7 @@ VOID TEST(KernelBufferTest, DefaultObject) | @@ -211,7 +211,7 @@ VOID TEST(KernelBufferTest, DefaultObject) | ||
| 211 | 211 | ||
| 212 | VOID TEST(KernelBufferTest, AppendBytes) | 212 | VOID TEST(KernelBufferTest, AppendBytes) |
| 213 | { | 213 | { |
| 214 | - SrsFastBuffer b; | 214 | + SrsSimpleBuffer b; |
| 215 | 215 | ||
| 216 | char winlin[] = "winlin"; | 216 | char winlin[] = "winlin"; |
| 217 | b.append(winlin, strlen(winlin)); | 217 | b.append(winlin, strlen(winlin)); |
| @@ -231,7 +231,7 @@ VOID TEST(KernelBufferTest, AppendBytes) | @@ -231,7 +231,7 @@ VOID TEST(KernelBufferTest, AppendBytes) | ||
| 231 | 231 | ||
| 232 | VOID TEST(KernelBufferTest, EraseBytes) | 232 | VOID TEST(KernelBufferTest, EraseBytes) |
| 233 | { | 233 | { |
| 234 | - SrsFastBuffer b; | 234 | + SrsSimpleBuffer b; |
| 235 | 235 | ||
| 236 | b.erase(0); | 236 | b.erase(0); |
| 237 | b.erase(-1); | 237 | b.erase(-1); |
| @@ -265,22 +265,21 @@ VOID TEST(KernelBufferTest, EraseBytes) | @@ -265,22 +265,21 @@ VOID TEST(KernelBufferTest, EraseBytes) | ||
| 265 | EXPECT_EQ(0, b.length()); | 265 | EXPECT_EQ(0, b.length()); |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | -VOID TEST(KernelBufferTest, Grow) | 268 | +VOID TEST(KernelFastBufferTest, Grow) |
| 269 | { | 269 | { |
| 270 | SrsFastBuffer b; | 270 | SrsFastBuffer b; |
| 271 | MockBufferReader r("winlin"); | 271 | MockBufferReader r("winlin"); |
| 272 | 272 | ||
| 273 | b.grow(&r, 1); | 273 | b.grow(&r, 1); |
| 274 | - EXPECT_EQ(6, b.length()); | ||
| 275 | - EXPECT_EQ('w', b.bytes()[0]); | 274 | + EXPECT_EQ('w', b.read_1byte()); |
| 276 | 275 | ||
| 277 | b.grow(&r, 3); | 276 | b.grow(&r, 3); |
| 278 | - EXPECT_EQ(6, b.length()); | ||
| 279 | - EXPECT_EQ('n', b.bytes()[2]); | 277 | + b.skip(1); |
| 278 | + EXPECT_EQ('n', b.read_1byte()); | ||
| 280 | 279 | ||
| 281 | b.grow(&r, 100); | 280 | b.grow(&r, 100); |
| 282 | - EXPECT_EQ(102, b.length()); | ||
| 283 | - EXPECT_EQ('l', b.bytes()[99]); | 281 | + b.skip(99); |
| 282 | + EXPECT_EQ('w', b.read_1byte()); | ||
| 284 | } | 283 | } |
| 285 | 284 | ||
| 286 | /** | 285 | /** |
| @@ -78,9 +78,9 @@ public: | @@ -78,9 +78,9 @@ public: | ||
| 78 | int64_t recv_bytes; | 78 | int64_t recv_bytes; |
| 79 | int64_t send_bytes; | 79 | int64_t send_bytes; |
| 80 | // data source for socket read. | 80 | // data source for socket read. |
| 81 | - SrsFastBuffer in_buffer; | 81 | + SrsSimpleBuffer in_buffer; |
| 82 | // data buffer for socket send. | 82 | // data buffer for socket send. |
| 83 | - SrsFastBuffer out_buffer; | 83 | + SrsSimpleBuffer out_buffer; |
| 84 | public: | 84 | public: |
| 85 | MockBufferIO(); | 85 | MockBufferIO(); |
| 86 | virtual ~MockBufferIO(); | 86 | virtual ~MockBufferIO(); |
-
请 注册 或 登录 后发表评论