for bug #251, remove the queue fast cache for it's too complex, use queue fast v…
…ector instead. 2.0.69
正在显示
4 个修改的文件
包含
3 行增加
和
123 行删除
| @@ -406,23 +406,10 @@ SrsConsumer::SrsConsumer(SrsSource* _source) | @@ -406,23 +406,10 @@ SrsConsumer::SrsConsumer(SrsSource* _source) | ||
| 406 | mw_duration = 0; | 406 | mw_duration = 0; |
| 407 | mw_waiting = false; | 407 | mw_waiting = false; |
| 408 | #endif | 408 | #endif |
| 409 | - | ||
| 410 | -#ifdef SRS_PERF_QUEUE_FAST_CACHE | ||
| 411 | - mw_cache = new SrsMessageArray(SRS_PERF_MW_MSGS); | ||
| 412 | - mw_count = 0; | ||
| 413 | - mw_first_pkt = mw_last_pkt = 0; | ||
| 414 | -#endif | ||
| 415 | } | 409 | } |
| 416 | 410 | ||
| 417 | SrsConsumer::~SrsConsumer() | 411 | SrsConsumer::~SrsConsumer() |
| 418 | { | 412 | { |
| 419 | -#ifdef SRS_PERF_QUEUE_FAST_CACHE | ||
| 420 | - if (mw_cache) { | ||
| 421 | - mw_cache->free(mw_count); | ||
| 422 | - mw_count = 0; | ||
| 423 | - } | ||
| 424 | - srs_freep(mw_cache); | ||
| 425 | -#endif | ||
| 426 | source->on_consumer_destroy(this); | 413 | source->on_consumer_destroy(this); |
| 427 | srs_freep(jitter); | 414 | srs_freep(jitter); |
| 428 | srs_freep(queue); | 415 | srs_freep(queue); |
| @@ -460,35 +447,9 @@ int SrsConsumer::enqueue(SrsSharedPtrMessage* __msg, bool atc, int tba, int tbv, | @@ -460,35 +447,9 @@ int SrsConsumer::enqueue(SrsSharedPtrMessage* __msg, bool atc, int tba, int tbv, | ||
| 460 | } | 447 | } |
| 461 | } | 448 | } |
| 462 | 449 | ||
| 463 | -#ifdef SRS_PERF_QUEUE_FAST_CACHE | ||
| 464 | - // use fast cache if available | ||
| 465 | - if (mw_count < mw_cache->max) { | ||
| 466 | - // update fast cache timestamps | ||
| 467 | - if (mw_count == 0) { | ||
| 468 | - mw_first_pkt = msg->timestamp; | ||
| 469 | - } | ||
| 470 | - mw_last_pkt = msg->timestamp; | ||
| 471 | - | ||
| 472 | - mw_cache->msgs[mw_count++] = msg; | ||
| 473 | - } else{ | ||
| 474 | - // fast cache is full, use queue. | ||
| 475 | - bool is_overflow = false; | ||
| 476 | - if ((ret = queue->enqueue(msg, &is_overflow)) != ERROR_SUCCESS) { | ||
| 477 | - return ret; | ||
| 478 | - } | ||
| 479 | - // when overflow, clear cache and refresh the fast cache. | ||
| 480 | - if (is_overflow) { | ||
| 481 | - mw_cache->free(mw_count); | ||
| 482 | - if ((ret = dumps_queue_to_fast_cache()) != ERROR_SUCCESS) { | ||
| 483 | - return ret; | ||
| 484 | - } | ||
| 485 | - } | ||
| 486 | - } | ||
| 487 | -#else | ||
| 488 | if ((ret = queue->enqueue(msg, NULL)) != ERROR_SUCCESS) { | 450 | if ((ret = queue->enqueue(msg, NULL)) != ERROR_SUCCESS) { |
| 489 | return ret; | 451 | return ret; |
| 490 | } | 452 | } |
| 491 | -#endif | ||
| 492 | 453 | ||
| 493 | #ifdef SRS_PERF_QUEUE_COND_WAIT | 454 | #ifdef SRS_PERF_QUEUE_COND_WAIT |
| 494 | // fire the mw when msgs is enough. | 455 | // fire the mw when msgs is enough. |
| @@ -522,31 +483,13 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count) | @@ -522,31 +483,13 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count) | ||
| 522 | if (paused) { | 483 | if (paused) { |
| 523 | return ret; | 484 | return ret; |
| 524 | } | 485 | } |
| 525 | - | ||
| 526 | -#ifdef SRS_PERF_QUEUE_FAST_CACHE | ||
| 527 | - // only dumps an whole array to msgs. | ||
| 528 | - for (int i = 0; i < mw_count; i++) { | ||
| 529 | - msgs->msgs[i] = mw_cache->msgs[i]; | ||
| 530 | - } | ||
| 531 | - count = mw_count; | ||
| 532 | - | ||
| 533 | - // when fast cache is not filled, | ||
| 534 | - // we donot check the queue, direclty zero fast cache. | ||
| 535 | - if (mw_count < mw_cache->max) { | ||
| 536 | - mw_count = 0; | ||
| 537 | - mw_first_pkt = mw_last_pkt = 0; | ||
| 538 | - return ret; | ||
| 539 | - } | ||
| 540 | - | ||
| 541 | - return dumps_queue_to_fast_cache(); | ||
| 542 | -#else | 486 | + |
| 543 | // pump msgs from queue. | 487 | // pump msgs from queue. |
| 544 | if ((ret = queue->dump_packets(msgs->max, msgs->msgs, count)) != ERROR_SUCCESS) { | 488 | if ((ret = queue->dump_packets(msgs->max, msgs->msgs, count)) != ERROR_SUCCESS) { |
| 545 | return ret; | 489 | return ret; |
| 546 | } | 490 | } |
| 547 | 491 | ||
| 548 | return ret; | 492 | return ret; |
| 549 | -#endif | ||
| 550 | } | 493 | } |
| 551 | 494 | ||
| 552 | #ifdef SRS_PERF_QUEUE_COND_WAIT | 495 | #ifdef SRS_PERF_QUEUE_COND_WAIT |
| @@ -554,19 +497,7 @@ void SrsConsumer::wait(int nb_msgs, int duration) | @@ -554,19 +497,7 @@ void SrsConsumer::wait(int nb_msgs, int duration) | ||
| 554 | { | 497 | { |
| 555 | mw_min_msgs = nb_msgs; | 498 | mw_min_msgs = nb_msgs; |
| 556 | mw_duration = duration; | 499 | mw_duration = duration; |
| 557 | - | ||
| 558 | -#ifdef SRS_PERF_QUEUE_FAST_CACHE | ||
| 559 | - // when fast cache not overflow, always flush. | ||
| 560 | - // so we donot care about the queue. | ||
| 561 | - bool fast_cache_overflow = mw_count >= mw_cache->max; | ||
| 562 | - int duration_ms = (int)(mw_last_pkt - mw_first_pkt); | ||
| 563 | - bool match_min_msgs = mw_count > mw_min_msgs; | ||
| 564 | - | ||
| 565 | - // when fast cache overflow, or duration ok, signal to flush. | ||
| 566 | - if (fast_cache_overflow || (match_min_msgs && duration_ms > mw_duration)) { | ||
| 567 | - return; | ||
| 568 | - } | ||
| 569 | -#else | 500 | + |
| 570 | int duration_ms = queue->duration(); | 501 | int duration_ms = queue->duration(); |
| 571 | bool match_min_msgs = queue->size() > mw_min_msgs; | 502 | bool match_min_msgs = queue->size() > mw_min_msgs; |
| 572 | 503 | ||
| @@ -574,7 +505,6 @@ void SrsConsumer::wait(int nb_msgs, int duration) | @@ -574,7 +505,6 @@ void SrsConsumer::wait(int nb_msgs, int duration) | ||
| 574 | if (match_min_msgs && duration_ms > mw_duration) { | 505 | if (match_min_msgs && duration_ms > mw_duration) { |
| 575 | return; | 506 | return; |
| 576 | } | 507 | } |
| 577 | -#endif | ||
| 578 | 508 | ||
| 579 | // the enqueue will notify this cond. | 509 | // the enqueue will notify this cond. |
| 580 | mw_waiting = true; | 510 | mw_waiting = true; |
| @@ -593,28 +523,6 @@ int SrsConsumer::on_play_client_pause(bool is_pause) | @@ -593,28 +523,6 @@ int SrsConsumer::on_play_client_pause(bool is_pause) | ||
| 593 | return ret; | 523 | return ret; |
| 594 | } | 524 | } |
| 595 | 525 | ||
| 596 | -#ifdef SRS_PERF_QUEUE_FAST_CACHE | ||
| 597 | -int SrsConsumer::dumps_queue_to_fast_cache() | ||
| 598 | -{ | ||
| 599 | - int ret =ERROR_SUCCESS; | ||
| 600 | - | ||
| 601 | - // fill fast cache with queue. | ||
| 602 | - if ((ret = queue->dump_packets(mw_cache->max, mw_cache->msgs, mw_count)) != ERROR_SUCCESS) { | ||
| 603 | - return ret; | ||
| 604 | - } | ||
| 605 | - // set the timestamp when got message. | ||
| 606 | - if (mw_count > 0) { | ||
| 607 | - SrsSharedPtrMessage* first_msg = mw_cache->msgs[0]; | ||
| 608 | - mw_first_pkt = first_msg->timestamp; | ||
| 609 | - | ||
| 610 | - SrsSharedPtrMessage* last_msg = mw_cache->msgs[mw_count - 1]; | ||
| 611 | - mw_last_pkt = last_msg->timestamp; | ||
| 612 | - } | ||
| 613 | - | ||
| 614 | - return ret; | ||
| 615 | -} | ||
| 616 | -#endif | ||
| 617 | - | ||
| 618 | SrsGopCache::SrsGopCache() | 526 | SrsGopCache::SrsGopCache() |
| 619 | { | 527 | { |
| 620 | cached_video_count = 0; | 528 | cached_video_count = 0; |
| @@ -205,16 +205,6 @@ private: | @@ -205,16 +205,6 @@ private: | ||
| 205 | int mw_min_msgs; | 205 | int mw_min_msgs; |
| 206 | int mw_duration; | 206 | int mw_duration; |
| 207 | #endif | 207 | #endif |
| 208 | -#ifdef SRS_PERF_QUEUE_FAST_CACHE | ||
| 209 | - // use fast cache for msgs | ||
| 210 | - // @see https://github.com/winlinvip/simple-rtmp-server/issues/251 | ||
| 211 | - SrsMessageArray* mw_cache; | ||
| 212 | - // the count of msg in fast cache. | ||
| 213 | - int mw_count; | ||
| 214 | - // the packet time in fast cache. | ||
| 215 | - int64_t mw_first_pkt; | ||
| 216 | - int64_t mw_last_pkt; | ||
| 217 | -#endif | ||
| 218 | public: | 208 | public: |
| 219 | SrsConsumer(SrsSource* _source); | 209 | SrsConsumer(SrsSource* _source); |
| 220 | virtual ~SrsConsumer(); | 210 | virtual ~SrsConsumer(); |
| @@ -262,14 +252,6 @@ public: | @@ -262,14 +252,6 @@ public: | ||
| 262 | * when client send the pause message. | 252 | * when client send the pause message. |
| 263 | */ | 253 | */ |
| 264 | virtual int on_play_client_pause(bool is_pause); | 254 | virtual int on_play_client_pause(bool is_pause); |
| 265 | -private: | ||
| 266 | -#ifdef SRS_PERF_QUEUE_FAST_CACHE | ||
| 267 | - /** | ||
| 268 | - * dumps the queue to fast cache, | ||
| 269 | - * when fast cache is clear or queue is overflow. | ||
| 270 | - */ | ||
| 271 | - virtual int dumps_queue_to_fast_cache(); | ||
| 272 | -#endif | ||
| 273 | }; | 255 | }; |
| 274 | 256 | ||
| 275 | /** | 257 | /** |
| @@ -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 68 | 34 | +#define VERSION_REVISION 69 |
| 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" |
| @@ -115,20 +115,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -115,20 +115,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 115 | */ | 115 | */ |
| 116 | #undef SRS_PERF_MW_SO_RCVBUF | 116 | #undef SRS_PERF_MW_SO_RCVBUF |
| 117 | /** | 117 | /** |
| 118 | -* whether enable the fast cache. | ||
| 119 | -* @remark this improve performance for large connectios. | ||
| 120 | -* @remark this also introduce complex, default to disable it. | ||
| 121 | -* @see https://github.com/winlinvip/simple-rtmp-server/issues/251 | ||
| 122 | -*/ | ||
| 123 | -#undef SRS_PERF_QUEUE_FAST_CACHE | ||
| 124 | -/** | ||
| 125 | * whether enable the fast vector for qeueue. | 118 | * whether enable the fast vector for qeueue. |
| 126 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/251 | 119 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/251 |
| 127 | */ | 120 | */ |
| 128 | #define SRS_PERF_QUEUE_FAST_VECTOR | 121 | #define SRS_PERF_QUEUE_FAST_VECTOR |
| 129 | -#if defined(SRS_PERF_QUEUE_FAST_CACHE) && defined(SRS_PERF_QUEUE_FAST_VECTOR) | ||
| 130 | - #error "fast cache conflict with fast vector" | ||
| 131 | -#endif | ||
| 132 | /** | 122 | /** |
| 133 | * whether use cond wait to send messages. | 123 | * whether use cond wait to send messages. |
| 134 | * @remark this improve performance for large connectios. | 124 | * @remark this improve performance for large connectios. |
-
请 注册 或 登录 后发表评论