From 18e8b147e66ba262b4d04a2270d1cae3d95b9a6f Mon Sep 17 00:00:00 2001 From: "J. Martin" Date: Thu, 23 Feb 2017 18:52:46 -0600 Subject: [PATCH] Limit the gem native build resources When building the native extension make -j can absorb all available resources on a system. Implement "reasonable" limits on the number of compiling jobs when the number of processors can be detected and use a conservative count when ruby version does not provide detection. --- src/ruby/ext/grpc/extconf.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index b379664bab8..ecb66239b90 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -27,6 +27,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +require 'etc' require 'mkmf' LIBDIR = RbConfig::CONFIG['libdir'] @@ -80,7 +81,9 @@ ENV['BUILDDIR'] = output_dir unless windows puts 'Building internal gRPC into ' + grpc_lib_dir - system("make -j -C #{grpc_root} #{grpc_lib_dir}/libgrpc.a CONFIG=#{grpc_config}") + nproc = 4 + nproc = Etc.nprocessors * 2 if Etc.respond_to? :nprocessors + system("make -j#{nproc} -C #{grpc_root} #{grpc_lib_dir}/libgrpc.a CONFIG=#{grpc_config}") exit 1 unless $? == 0 end