Skip to content

Commit

Permalink
Only set JRE -Xmx if user has not done so.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikkelSchubert committed May 7, 2015
1 parent 5682381 commit 2fc2560
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions pypeline/atomiccmd/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,31 +322,6 @@ def __init__(self, jar, jre_options=(), temp_root="%(TEMP_DIR)s",
"-Djava.io.tmpdir=%s" % temp_root,
"-Djava.awt.headless=true"]

# Our experience is that the default -Xmx value tends to cause
# OutOfMemory exceptions with typical datasets, so require at least
# 4gb. However, this is not possible on 32bit systems, which cannot
# handle such datasets in any case (due to e.g. BWA memory usage).
if AtomicJavaCmdBuilder._IS_JAVA_64_BIT is None:
with open("/dev/null", "w") as dev_null:
version_call = call + ["-d64", "-version"]
try:
result = subprocess.call(version_call,
stdout=dev_null,
stderr=dev_null,
preexec_fn=os.setsid,
close_fds=True)

AtomicJavaCmdBuilder._IS_JAVA_64_BIT = (result == 0)
except OSError:
# We don't care if this fails here, the exec / version
# checks will report any problems downstream
AtomicJavaCmdBuilder._IS_JAVA_64_BIT = False

# The default memory-limit tends to be insufficent for whole-genome
# datasets, so this is increased on 64-bit architectures.
if AtomicJavaCmdBuilder._IS_JAVA_64_BIT:
call.append("-Xmx4g")

if not isinstance(gc_threads, (types.IntType, types.LongType)):
raise TypeError("'gc_threads' must be an integer value, not %r"
% gc_threads.__class__.__name__)
Expand All @@ -358,8 +333,36 @@ def __init__(self, jar, jre_options=(), temp_root="%(TEMP_DIR)s",
raise ValueError("'gc_threads' must be a 1 or greater, not %r"
% gc_threads)

jre_options = tuple(jre_options)
call.extend(jre_options)

# Only set -Xmx if no user-supplied setting is given
if not any(opt.startswith("-Xmx") for opt in jre_options):
# Our experience is that the default -Xmx value tends to cause
# OutOfMemory exceptions with typical datasets, so require at least
# 4gb. However, this is not possible on 32bit systems, which cannot
# handle such datasets in any case (due to e.g. BWA memory usage).
if AtomicJavaCmdBuilder._IS_JAVA_64_BIT is None:
with open("/dev/null", "w") as dev_null:
version_call = call + ["-d64", "-version"]
try:
result = subprocess.call(version_call,
stdout=dev_null,
stderr=dev_null,
preexec_fn=os.setsid,
close_fds=True)

AtomicJavaCmdBuilder._IS_JAVA_64_BIT = (result == 0)
except OSError:
# We don't care if this fails here, the exec / version
# checks will report any problems downstream
AtomicJavaCmdBuilder._IS_JAVA_64_BIT = False

# The default memory-limit tends to be insufficent for whole-genome
# datasets, so this is increased on 64-bit architectures.
if AtomicJavaCmdBuilder._IS_JAVA_64_BIT:
call.append("-Xmx4g")

version = self._get_java_version(java_version)
call.extend(("-jar", "%(AUX_JAR)s"))
AtomicCmdBuilder.__init__(self, call,
Expand Down

0 comments on commit 2fc2560

Please sign in to comment.