From 01d187cb801a3c0462af337a8f0b6f0e2b1f2ec3 Mon Sep 17 00:00:00 2001 From: veeve Date: Tue, 26 Feb 2008 05:12:08 +0000 Subject: [PATCH] add increase_max_fds to the new TServer.cpp Summary: - added TServer.cpp - increase_max_fds() defaults to 2^24. Reviewed By: dreiss Test Plan: - Linked this code into chatloggerd and verified the return value. Revert: OK TracCamp Project: Chirp DiffCamp Revision: 8275 git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665500 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/Makefile.am | 1 + lib/cpp/src/server/TServer.cpp | 25 +++++++++++++++++++++++++ lib/cpp/src/server/TServer.h | 8 ++++++++ 3 files changed, 34 insertions(+) create mode 100644 lib/cpp/src/server/TServer.cpp diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am index 356afff5..07540a1e 100644 --- a/lib/cpp/Makefile.am +++ b/lib/cpp/Makefile.am @@ -40,6 +40,7 @@ libthrift_la_SOURCES = src/Thrift.cpp \ src/transport/TSocketPool.cpp \ src/transport/TServerSocket.cpp \ src/transport/TTransportUtils.cpp \ + src/server/TServer.cpp \ src/server/TSimpleServer.cpp \ src/server/TThreadPoolServer.cpp \ src/server/TThreadedServer.cpp \ diff --git a/lib/cpp/src/server/TServer.cpp b/lib/cpp/src/server/TServer.cpp new file mode 100644 index 00000000..6febf982 --- /dev/null +++ b/lib/cpp/src/server/TServer.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2006- Facebook +// Distributed under the Thrift Software License +// +// See accompanying file LICENSE or visit the Thrift site at: +// http://developers.facebook.com/thrift/ + +#include +#include +#include + +namespace facebook { namespace thrift { namespace server { + +int increase_max_fds(int max_fds=(1<<24)) { + struct rlimit fdmaxrl; + + for(fdmaxrl.rlim_cur = max_fds, fdmaxrl.rlim_max = max_fds; + max_fds && (setrlimit(RLIMIT_NOFILE, &fdmaxrl) < 0); + fdmaxrl.rlim_cur = max_fds, fdmaxrl.rlim_max = max_fds) { + max_fds /= 2; + } + + return fdmaxrl.rlim_cur; +} + +}}} // facebook::thrift::server diff --git a/lib/cpp/src/server/TServer.h b/lib/cpp/src/server/TServer.h index d7245c7c..f05b2ebb 100644 --- a/lib/cpp/src/server/TServer.h +++ b/lib/cpp/src/server/TServer.h @@ -188,6 +188,14 @@ public: }; +/** + * Helper function to increase the max file descriptors limit + * for the current process and all of its children. + * By default, tries to increase it to as much as 2^24. + */ + int increase_max_fds(int max_fds=(1<<24)); + + }}} // facebook::thrift::server #endif // #ifndef _THRIFT_SERVER_TSERVER_H_ -- 2.17.1