diff --git a/README.md b/README.md index af053f02b7..5be3152dfe 100755 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ cd srs/trunk * Usage: How to delivery HLS by embeded HTTP server?([CN][v3_CN_SampleHTTP], [EN][v3_EN_SampleHTTP]) * Usage: How to run the demostration of SRS? ([CN][v1_CN_SampleDemo], [EN][v1_EN_SampleDemo]) * Usage: How to publish h.264 raw stream as RTMP? ([CN][v3_CN_SrsLibrtmp2], [EN][v3_EN_SrsLibrtmp2]) +* Usage: How to improve performance by multiple CPUs? ([CN][v3_CN_REUSEPORT], [EN][v3_EN_REUSEPORT]) * Usage: Who are using SRS?([CN][v1_CN_Sample]) * Usage: Why choose SRS? About the milestone and product plan? ([CN][v1_CN_Product], [EN][v1_EN_Product]) @@ -148,6 +149,7 @@ Please select according to languages: - [x] Enhanced RTMP url which supports vhost in stream, read [#1059][bug #1059]. - [x] Support origin cluster, please read [#464][bug #464], [RTMP 302][bug #92]. - [x] Support listen at IPv4 and IPv6, read [#460][bug #460]. +- [x] Support SO_REUSEPORT, read [#775][bug #775]. - [ ] Utest cover almost all kernel code. - [ ] Enhanced forwarding with vhost and variables. - [ ] Support source cleanup for idle streams. @@ -164,6 +166,7 @@ Please select according to languages: ### V3 changes +* v3.0, 2019-10-03, Fix [#775][bug #775], Support SO_REUSEPORT. 3.0.54 * v3.0, 2019-10-03, Remove KAFKA. 3.0.53 * v3.0, 2019-05-14, Covert Kernel File reader/writer. 3.0.52 * v3.0, 2019-04-30, Refine typo in files. 3.0.51 @@ -782,7 +785,7 @@ The performance benchmark data and corelative commits are listed here. * See also: [Performance for x86/x64 Test Guide][v1_CN_Performance]. * See also: [Performance for RaspberryPi][v1_CN_RaspberryPi]. -* For multiple processes performance, read [go-oryx][oryx]. +* For multiple processes performance, read [#775: REUSEPORT][bug #775] or [go-oryx][oryx]. #### Play RTMP benchmark @@ -1474,6 +1477,7 @@ Winlin [bug #821]: https://github.com/ossrs/srs/issues/821 [bug #913]: https://github.com/ossrs/srs/issues/913 [bug #460]: https://github.com/ossrs/srs/issues/460 +[bug #775]: https://github.com/ossrs/srs/issues/775 [bug #1057]: https://github.com/ossrs/srs/issues/1057 [bug #105]: https://github.com/ossrs/srs/issues/105 [bug #727]: https://github.com/ossrs/srs/issues/727 diff --git a/trunk/conf/edge2.conf b/trunk/conf/edge2.conf new file mode 100644 index 0000000000..193238d88d --- /dev/null +++ b/trunk/conf/edge2.conf @@ -0,0 +1,15 @@ +# the config for srs origin-edge cluster +# @see https://github.com/ossrs/srs/wiki/v1_CN_Edge +# @see full.conf for detail config. + +listen 1935; +max_connections 1000; +pid objs/edge2.pid; +daemon off; +srs_log_tank console; +vhost __defaultVhost__ { + cluster { + mode remote; + origin 127.0.0.1:19350; + } +} diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 9ea41f532d..46c5908730 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -27,7 +27,7 @@ // The version config. #define VERSION_MAJOR 3 #define VERSION_MINOR 0 -#define VERSION_REVISION 53 +#define VERSION_REVISION 54 // The macros generated by configure script. #include diff --git a/trunk/src/service/srs_service_st.cpp b/trunk/src/service/srs_service_st.cpp index 7b595baaae..e4ffe26691 100644 --- a/trunk/src/service/srs_service_st.cpp +++ b/trunk/src/service/srs_service_st.cpp @@ -110,6 +110,16 @@ srs_error_t srs_fd_reuseaddr(int fd) return srs_success; } +srs_error_t srs_fd_reuseport(int fd) +{ + int v = 1; + if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &v, sizeof(int)) == -1) { + return srs_error_new(ERROR_SOCKET_SETREUSEADDR, "SO_REUSEPORT fd=%v", fd); + } + + return srs_success; +} + srs_error_t srs_fd_keepalive(int fd) { #ifdef SO_KEEPALIVE @@ -215,6 +225,11 @@ srs_error_t srs_tcp_listen(std::string ip, int port, srs_netfd_t* pfd) return srs_error_wrap(err, "set reuseaddr fd=%d", fd); } + if ((err = srs_fd_reuseport(fd)) != srs_success) { + ::close(fd); + return srs_error_wrap(err, "set reuseport fd=%d", fd); + } + if (bind(fd, r->ai_addr, r->ai_addrlen) == -1) { ::close(fd); return srs_error_new(ERROR_SOCKET_BIND, "bind fd=%d", fd); @@ -269,6 +284,11 @@ srs_error_t srs_udp_listen(std::string ip, int port, srs_netfd_t* pfd) return srs_error_wrap(err, "set reuseaddr fd=%d", fd); } + if ((err = srs_fd_reuseport(fd)) != srs_success) { + ::close(fd); + return srs_error_wrap(err, "set reuseport fd=%d", fd); + } + if (bind(fd, r->ai_addr, r->ai_addrlen) == -1) { ::close(fd); return srs_error_new(ERROR_SOCKET_BIND, "bind fd=%d", fd); diff --git a/trunk/src/service/srs_service_st.hpp b/trunk/src/service/srs_service_st.hpp index 4bb02a5b52..2c8174ab2c 100644 --- a/trunk/src/service/srs_service_st.hpp +++ b/trunk/src/service/srs_service_st.hpp @@ -49,6 +49,9 @@ extern srs_error_t srs_fd_closeexec(int fd); // Set the SO_REUSEADDR of fd. extern srs_error_t srs_fd_reuseaddr(int fd); +// Set the SO_REUSEPORT of fd. +extern srs_error_t srs_fd_reuseport(int fd); + // Set the SO_KEEPALIVE of fd. extern srs_error_t srs_fd_keepalive(int fd);