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.
pull/9862/head
J. Martin 8 years ago
parent ed7d06af3e
commit 18e8b147e6
No known key found for this signature in database
GPG Key ID: AB05A8BF21EEB881
  1. 5
      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

Loading…
Cancel
Save