Skip to content

Commit

Permalink
Merge in few features from the private version:
Browse files Browse the repository at this point in the history
o Warn user when rtpproxy is about to consume 80% of file descriptors
allowed by the "hard" RLIMIT_NOFILE limit, suggesting user to use
appropriate command-line option to get this limit increased. To avoid
spamming the log file the warning is displayed only once.

o Call getrlimit(2) after setrlimit(2) to detect if kernel has actually set
limit to requested value or not. Warn user if the value of actual limit
returned by the kernel is lower than a requested one.

o Clarify ``I'' command, extending it with display of both active channels
and active session. Channel is RTP/RTCP session to one endpoint, whereas
session is two channels glued together with the forwarding logic.
  • Loading branch information
sobomax committed Mar 31, 2008
1 parent ddc37e1 commit 1fe90b5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
41 changes: 33 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: main.c,v 1.65 2008/03/18 02:26:29 sobomax Exp $
* $Id: main.c,v 1.66 2008/03/31 20:35:39 sobomax Exp $
*
*/

Expand Down Expand Up @@ -217,6 +217,7 @@ remove_session(struct cfg *cf, struct rtpp_session *sp)
rtp_resizer_free(&sp->resizers[0]);
rtp_resizer_free(&sp->resizers[1]);
free(sp);
cf->sessions_active--;
}

static int
Expand Down Expand Up @@ -479,11 +480,13 @@ handle_command(struct cfg *cf, int controlfd)
case 'i':
case 'I':
if (cookie == NULL)
len = sprintf(buf, "sessions created: %llu\nactive sessions: %d\n",
cf->sessions_created, cf->nsessions / 2);
len = sprintf(buf, "sessions created: %llu\nactive sessions: %d\n"
"active streams: %d\n", cf->sessions_created,
cf->sessions_active, cf->nsessions / 2);
else
len = sprintf(buf, "%s sessions created: %llu\nactive sessions: %d\n",
cookie, cf->sessions_created, cf->nsessions / 2);
len = sprintf(buf, "%s sessions created: %llu\nactive sessions: %d\n"
"active streams: %d\n", cookie, cf->sessions_created,
cf->sessions_active, cf->nsessions / 2);
for (i = 1; i < cf->nsessions; i++) {
char addrs[4][256];

Expand Down Expand Up @@ -918,6 +921,20 @@ handle_command(struct cfg *cf, int controlfd)
append_session(cf, spb, 1);

cf->sessions_created++;
cf->sessions_active++;
/*
* Each session can consume up to 5 open file descriptors (2 RTP,
* 2 RTCP and 1 logging) so that warn user when he is likely to
* exceed 80% mark on hard limit.
*/
if (cf->sessions_active > (cf->nofile_limit.rlim_max * 80 / (100 * 5)) &&
cf->nofile_limit_warned == 0) {
cf->nofile_limit_warned = 1;
rtpp_log_write(RTPP_LOG_WARN, cf->glog, "passed 80%% "
"threshold on the open file descriptors limit (%d), "
"consider increasing the limit using -L command line "
"option", cf->nofile_limit.rlim_max);
}

rtpp_log_write(RTPP_LOG_INFO, spa->log, "new session on a port %d created, "
"tag %s", lport, from_tag);
Expand Down Expand Up @@ -1046,7 +1063,6 @@ static void
init_config(struct cfg *cf, int argc, char **argv)
{
int ch, i;
struct rlimit lim;
char *bh[2], *bh6[2], *cp;

bh[0] = bh[1] = bh6[0] = bh6[1] = NULL;
Expand All @@ -1058,6 +1074,9 @@ init_config(struct cfg *cf, int argc, char **argv)
cf->tos = TOS;
cf->rrtcp = 1;

if (getrlimit(RLIMIT_NOFILE, &(cf->nofile_limit)) != 0)
err(1, "getrlimit");

while ((ch = getopt(argc, argv, "vf2Rl:6:s:S:t:r:p:T:L:m:M:u:F")) != -1)
switch (ch) {
case 'f':
Expand Down Expand Up @@ -1136,9 +1155,15 @@ init_config(struct cfg *cf, int argc, char **argv)
break;

case 'L':
lim.rlim_cur = lim.rlim_max = atoi(optarg);
if (setrlimit(RLIMIT_NOFILE, &lim) != 0)
cf->nofile_limit.rlim_cur = cf->nofile_limit.rlim_max = atoi(optarg);
if (setrlimit(RLIMIT_NOFILE, &(cf->nofile_limit)) != 0)
err(1, "setrlimit");
if (getrlimit(RLIMIT_NOFILE, &(cf->nofile_limit)) != 0)
err(1, "getrlimit");
if (cf->nofile_limit.rlim_max < atoi(optarg))
warnx("limit allocated by setrlimit (%d) is less than "
"requested (%d)", (int) cf->nofile_limit.rlim_max,
atoi(optarg));
break;

case 'm':
Expand Down
10 changes: 9 additions & 1 deletion rtpp_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: rtpp_defines.h,v 1.7 2007/12/18 23:02:02 sobomax Exp $
* $Id: rtpp_defines.h,v 1.8 2008/03/31 20:35:39 sobomax Exp $
*
*/

#ifndef _RTPP_DEFINES_H_
#define _RTPP_DEFINES_H_

#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <poll.h>

/*
Expand Down Expand Up @@ -71,6 +74,7 @@ struct cfg {
int nsessions;
int rtp_nsessions;
unsigned long long sessions_created;
int sessions_active;
int max_ttl;
/*
* The first address is for external interface, the second one - for
Expand All @@ -83,6 +87,10 @@ struct cfg {
const char *sdir;
int rrtcp; /* Whether or not to relay RTCP? */
rtpp_log_t glog;

struct rlimit nofile_limit;
int nofile_limit_warned;

char *run_uname;
char *run_gname;
int no_check;
Expand Down

0 comments on commit 1fe90b5

Please sign in to comment.