ABAO77 commited on
Commit
409ca74
·
verified ·
1 Parent(s): 9140001

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -447,8 +447,6 @@ class CodeExecutor:
447
 
448
  return self._combine_results(results, main_files)
449
 
450
- # Thay thế method _execute_java trong CodeExecutor class
451
-
452
  async def _execute_java(
453
  self,
454
  main_files: List[str],
@@ -461,25 +459,28 @@ class CodeExecutor:
461
  java_files = list(Path(workspace).glob("*.java"))
462
  needs_compilation = len(java_files) > 0
463
 
464
- # JVM options for container environment
465
  jvm_opts = [
466
- "-Xms16m", # Initial heap size
467
- "-Xmx128m", # Maximum heap size
468
- "-XX:ReservedCodeCacheSize=16m", # Code cache size
469
- "-XX:InitialCodeCacheSize=2m", # Initial code cache
470
- "-XX:+UseSerialGC", # Simple GC for small apps
471
- "-XX:+TieredCompilation", # Enable tiered compilation
472
- "-XX:TieredStopAtLevel=1", # Stop at level 1 (faster startup)
473
- "-XX:+UseStringDeduplication", # Save memory on strings
474
- "-XX:MaxRAMPercentage=10.0", # Limit RAM usage to 10% of container
 
 
 
475
  ]
476
 
477
  # If we have .java files, compile them
478
  if needs_compilation:
479
  logger.info(f"Found {len(java_files)} Java source files, compiling...")
480
 
481
- # Compile with memory-optimized javac
482
- compile_cmd = ["javac", "-J-Xmx64m"] + [str(f) for f in java_files]
483
 
484
  compile_process = await asyncio.create_subprocess_exec(
485
  *compile_cmd,
 
447
 
448
  return self._combine_results(results, main_files)
449
 
 
 
450
  async def _execute_java(
451
  self,
452
  main_files: List[str],
 
459
  java_files = list(Path(workspace).glob("*.java"))
460
  needs_compilation = len(java_files) > 0
461
 
462
+ # JVM options for very limited container environment (HuggingFace)
463
  jvm_opts = [
464
+ "-Xms8m", # Minimal initial heap
465
+ "-Xmx64m", # Very small max heap
466
+ "-XX:ReservedCodeCacheSize=8m", # Minimal code cache
467
+ "-XX:InitialCodeCacheSize=1m", # Tiny initial code cache
468
+ "-XX:+UseSerialGC", # Simple GC
469
+ "-XX:NewRatio=3", # Small young generation
470
+ "-XX:SurvivorRatio=4", # Optimize survivor space
471
+ "-XX:MaxMetaspaceSize=32m", # Limit metaspace
472
+ "-XX:CompressedClassSpaceSize=8m", # Compress class space
473
+ "-Xss256k", # Small stack size
474
+ "-XX:-TieredCompilation", # Disable tiered compilation to save memory
475
+ "-Djava.awt.headless=true", # Headless mode
476
  ]
477
 
478
  # If we have .java files, compile them
479
  if needs_compilation:
480
  logger.info(f"Found {len(java_files)} Java source files, compiling...")
481
 
482
+ # Compile with minimal memory for javac
483
+ compile_cmd = ["javac", "-J-Xmx32m", "-J-Xms8m"] + [str(f) for f in java_files]
484
 
485
  compile_process = await asyncio.create_subprocess_exec(
486
  *compile_cmd,