diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index ecaed2168..d42d4de18 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -37,7 +37,7 @@ SrsConnection::SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd) // so we never use joinable. // TODO: FIXME: maybe other thread need to stop it. // @see: https://github.com/winlinvip/simple-rtmp-server/issues/78 - pthread = new SrsThread(this, 0, false); + pthread = new SrsThread("conn", this, 0, false); } SrsConnection::~SrsConnection() diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 78dd39cd8..37d9ef941 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -69,7 +69,7 @@ SrsEdgeIngester::SrsEdgeIngester() origin_index = 0; stream_id = 0; stfd = NULL; - pthread = new SrsThread(this, SRS_EDGE_INGESTER_SLEEP_US, true); + pthread = new SrsThread("edge-igs", this, SRS_EDGE_INGESTER_SLEEP_US, true); } SrsEdgeIngester::~SrsEdgeIngester() @@ -386,7 +386,7 @@ SrsEdgeForwarder::SrsEdgeForwarder() origin_index = 0; stream_id = 0; stfd = NULL; - pthread = new SrsThread(this, SRS_EDGE_FORWARDER_SLEEP_US, true); + pthread = new SrsThread("edge-fwr", this, SRS_EDGE_FORWARDER_SLEEP_US, true); queue = new SrsMessageQueue(); send_error_code = ERROR_SUCCESS; } diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp index 6aedcd152..25d62063f 100644 --- a/trunk/src/app/srs_app_encoder.cpp +++ b/trunk/src/app/srs_app_encoder.cpp @@ -44,7 +44,7 @@ static std::vector _transcoded_url; SrsEncoder::SrsEncoder() { - pthread = new SrsThread(this, SRS_RTMP_ENCODER_SLEEP_US, true); + pthread = new SrsThread("encoder", this, SRS_RTMP_ENCODER_SLEEP_US, true); pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_ENCODER); } diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index 1c1dbb2d5..52b62256b 100644 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -58,7 +58,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source) kbps = new SrsKbps(); stream_id = 0; - pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_US, true); + pthread = new SrsThread("forward", this, SRS_FORWARDER_SLEEP_US, true); queue = new SrsMessageQueue(); jitter = new SrsRtmpJitter(); diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index 7c5f6a1de..6658dddc4 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -36,7 +36,7 @@ using namespace std; // when error, ingester sleep for a while and retry. // ingest never sleep a long time, for we must start the stream ASAP. -#define SRS_AUTO_INGESTER_SLEEP_US (int64_t)(6*100*1000LL) +#define SRS_AUTO_INGESTER_SLEEP_US (int64_t)(3*1000*1000LL) SrsIngesterFFMPEG::SrsIngesterFFMPEG(SrsFFMPEG* _ffmpeg, string _vhost, string _id) { @@ -54,7 +54,7 @@ SrsIngester::SrsIngester() { _srs_config->subscribe(this); - pthread = new SrsThread(this, SRS_AUTO_INGESTER_SLEEP_US, true); + pthread = new SrsThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US, true); pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_INGESTER); } diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 4a2b02723..8ab29ebc3 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -40,7 +40,7 @@ SrsRecvThread::SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtm timeout = timeout_ms; handler = msg_handler; rtmp = rtmp_sdk; - trd = new SrsThread(this, 0, true); + trd = new SrsThread("recv", this, 0, true); } SrsRecvThread::~SrsRecvThread() diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index bb1d29ed5..b1d4abd5c 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -53,9 +53,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // system interval in ms, // all resolution times should be times togother, -// for example, system-time is 3(300ms), -// then rusage can be 3*x, for instance, 3*10=30(3s), -// the meminfo canbe 30*x, for instance, 30*2=60(6s) +// for example, system-interval is x=1s(1000ms), +// then rusage can be 3*x, for instance, 3*1=3s, +// the meminfo canbe 6*x, for instance, 6*1=6s, // for performance refine, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194 // @remark, recomment to 1000ms. #define SRS_SYS_CYCLE_INTERVAL 1000 @@ -63,7 +63,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // update time interval: // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES // @see SYS_TIME_RESOLUTION_US -#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 3 +#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 1 // update rusage interval: // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_RUSAGE_RESOLUTION_TIMES @@ -102,7 +102,7 @@ SrsListener::SrsListener(SrsServer* server, SrsListenerType type) _server = server; _type = type; - pthread = new SrsThread(this, 0, true); + pthread = new SrsThread("listen", this, 0, true); } SrsListener::~SrsListener() @@ -215,7 +215,7 @@ SrsSignalManager::SrsSignalManager(SrsServer* server) _server = server; sig_pipe[0] = sig_pipe[1] = -1; - pthread = new SrsThread(this, 0, true); + pthread = new SrsThread("signal", this, 0, true); signal_read_stfd = NULL; } @@ -714,7 +714,7 @@ int SrsServer::do_cycle() srs_trace("reload config success."); } - // update the cache time or rusage. + // update the cache time if ((i % SRS_SYS_TIME_RESOLUTION_MS_TIMES) == 0) { srs_info("update current time cache."); srs_update_system_time_ms(); diff --git a/trunk/src/app/srs_app_thread.cpp b/trunk/src/app/srs_app_thread.cpp index 857f5fe8e..74dcfeeb4 100644 --- a/trunk/src/app/srs_app_thread.cpp +++ b/trunk/src/app/srs_app_thread.cpp @@ -54,8 +54,9 @@ void ISrsThreadHandler::on_thread_stop() { } -SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable) +SrsThread::SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable) { + _name = name; handler = thread_handler; cycle_interval_us = interval_us; @@ -86,7 +87,7 @@ int SrsThread::start() int ret = ERROR_SUCCESS; if(tid) { - srs_info("thread already running."); + srs_info("thread %s already running.", _name); return ret; } @@ -141,7 +142,7 @@ void SrsThread::thread_cycle() int ret = ERROR_SUCCESS; _srs_context->generate_id(); - srs_info("thread cycle start"); + srs_info("thread %s cycle start", _name); _cid = _srs_context->get_id(); @@ -155,24 +156,24 @@ void SrsThread::thread_cycle() while (loop) { if ((ret = handler->on_before_cycle()) != ERROR_SUCCESS) { - srs_warn("thread on before cycle failed, ignored and retry, ret=%d", ret); + srs_warn("thread %s on before cycle failed, ignored and retry, ret=%d", _name, ret); goto failed; } - srs_info("thread on before cycle success"); + srs_info("thread %s on before cycle success"); if ((ret = handler->cycle()) != ERROR_SUCCESS) { if (!srs_is_client_gracefully_close(ret)) { - srs_warn("thread cycle failed, ignored and retry, ret=%d", ret); + srs_warn("thread cycle failed, ignored and retry, ret=%d", _name, ret); } goto failed; } - srs_info("thread cycle success"); + srs_info("thread %s cycle success", _name); if ((ret = handler->on_end_cycle()) != ERROR_SUCCESS) { - srs_warn("thread on end cycle failed, ignored and retry, ret=%d", ret); + srs_warn("thread %s on end cycle failed, ignored and retry, ret=%d", _name, ret); goto failed; } - srs_info("thread on end cycle success"); + srs_info("thread %s on end cycle success", _name); failed: if (!loop) { @@ -187,7 +188,7 @@ failed: } handler->on_thread_stop(); - srs_info("thread cycle finished"); + srs_info("thread %s cycle finished", _name); } void* SrsThread::thread_fun(void* arg) diff --git a/trunk/src/app/srs_app_thread.hpp b/trunk/src/app/srs_app_thread.hpp index debfd216f..347e6ceae 100644 --- a/trunk/src/app/srs_app_thread.hpp +++ b/trunk/src/app/srs_app_thread.hpp @@ -88,23 +88,26 @@ private: bool loop; bool can_run; bool _joinable; + const char* _name; private: ISrsThreadHandler* handler; int64_t cycle_interval_us; public: /** * initialize the thread. + * @param name, human readable name for st debug. * @param thread_handler, the cycle handler for the thread. * @param interval_us, the sleep interval when cycle finished. * @param joinable, if joinable, other thread must stop the thread. * @remark if joinable, thread never quit itself, or memory leak. * @see: https://github.com/winlinvip/simple-rtmp-server/issues/78 + * @remark about st debug, see st-1.9/README, _st_iterate_threads_flag */ /** * TODO: FIXME: maybe all thread must be reap by others threads, * @see: https://github.com/winlinvip/simple-rtmp-server/issues/77 */ - SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable); + SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable); virtual ~SrsThread(); public: /**