Skip to content

Instantly share code, notes, and snippets.

@radamuz
Forked from qrtt1/setenv.sh
Last active September 24, 2024 07:26
Show Gist options
  • Select an option

  • Save radamuz/7d4c23a06a003d8f062e98bb2bd9cd69 to your computer and use it in GitHub Desktop.

Select an option

Save radamuz/7d4c23a06a003d8f062e98bb2bd9cd69 to your computer and use it in GitHub Desktop.

Revisions

  1. radamuz revised this gist Sep 24, 2024. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions setenv.sh
    Original file line number Diff line number Diff line change
    @@ -9,18 +9,18 @@ if [ ! -f /proc/meminfo ]; then
    fi
    # Lee la primera línea del archivo /proc/meminfo que contiene "MemTotal"
    line=$(grep -m 1 "MemTotal" /proc/meminfo)
    line=\$(grep -m 1 "MemTotal" /proc/meminfo)
    # Verifica si la línea contiene la palabra "MemTotal" y "kB"
    if [[ "$line" == *"MemTotal"* && "$line" == *"kB"* ]]; then
    if [[ "\$line" == *"MemTotal"* && "\$line" == *"kB"* ]]; then
    # Extrae el valor numérico de la memoria
    memory_kb=$(echo $line | grep -oP '\d+')
    memory_kb=\$(echo \$line | grep -oP '\d+')
    # Si se pudo extraer el valor
    if [ -n "$memory_kb" ]; then
    if [ -n "\$memory_kb" ]; then
    # Calcula el 90% de la memoria en kB y conviértela a MB
    memory_mb=$(echo "($memory_kb * 0.9) / 1024" | bc)
    echo "$memory_mb"
    memory_mb=\$(echo "(\$memory_kb * 0.9) / 1024" | bc)
    echo "\$memory_mb"
    else
    echo 1024
    fi
  2. radamuz revised this gist Sep 24, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion setenv.sh
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ else
    fi
    EOF

    memory_max_mb=$(python $memory_estimate_script)
    memory_max_mb=$(bash $memory_estimate_script)

    export JAVA_HOME=/opt/java
    export JAVA_OPTS="-Xms512m -Xmx"$memory_max_mb"m -XX:+UseParallelGC -Duser.timezone=Asia/Taipei -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "
  3. radamuz revised this gist Sep 24, 2024. 1 changed file with 25 additions and 13 deletions.
    38 changes: 25 additions & 13 deletions setenv.sh
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,32 @@
    memory_estimate_script=$(mktemp /tmp/tmp.XXXXXXXXXX)
    cat << EOF > $memory_estimate_script
    import re
    import os.path
    #!/bin/bash
    if not os.path.exists("/proc/meminfo"): print(1024)
    # Verifica si existe el archivo /proc/meminfo
    if [ ! -f /proc/meminfo ]; then
    echo 1024
    exit 0
    fi
    with open("/proc/meminfo") as fh:
    line = fh.readline()
    if "MemTotal" in line and "kB" in line:
    m = re.search("\d+", line)
    if m:
    memory_kb = float(m.group()) * 0.9
    memory_mb = int(memory_kb / 1024)
    print(memory_mb)
    else:
    print(1024)
    # Lee la primera línea del archivo /proc/meminfo que contiene "MemTotal"
    line=$(grep -m 1 "MemTotal" /proc/meminfo)
    # Verifica si la línea contiene la palabra "MemTotal" y "kB"
    if [[ "$line" == *"MemTotal"* && "$line" == *"kB"* ]]; then
    # Extrae el valor numérico de la memoria
    memory_kb=$(echo $line | grep -oP '\d+')
    # Si se pudo extraer el valor
    if [ -n "$memory_kb" ]; then
    # Calcula el 90% de la memoria en kB y conviértela a MB
    memory_mb=$(echo "($memory_kb * 0.9) / 1024" | bc)
    echo "$memory_mb"
    else
    echo 1024
    fi
    else
    echo 1024
    fi
    EOF

    memory_max_mb=$(python $memory_estimate_script)
  4. radamuz revised this gist Sep 24, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion setenv.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ with open("/proc/meminfo") as fh:
    if "MemTotal" in line and "kB" in line:
    m = re.search("\d+", line)
    if m:
    memory_kb = float(m.group()) * 0.7
    memory_kb = float(m.group()) * 0.9
    memory_mb = int(memory_kb / 1024)
    print(memory_mb)
    else:
  5. radamuz revised this gist Sep 24, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions setenv.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ cat << EOF > $memory_estimate_script
    import re
    import os.path
    if not os.path.exists("/proc/meminfo"): print 1024
    if not os.path.exists("/proc/meminfo"): print(1024)
    with open("/proc/meminfo") as fh:
    line = fh.readline()
    @@ -12,9 +12,9 @@ with open("/proc/meminfo") as fh:
    if m:
    memory_kb = float(m.group()) * 0.7
    memory_mb = int(memory_kb / 1024)
    print memory_mb
    print(memory_mb)
    else:
    print 1024
    print(1024)
    EOF

    memory_max_mb=$(python $memory_estimate_script)
  6. @qrtt1 qrtt1 created this gist Sep 5, 2014.
    24 changes: 24 additions & 0 deletions setenv.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    memory_estimate_script=$(mktemp /tmp/tmp.XXXXXXXXXX)
    cat << EOF > $memory_estimate_script
    import re
    import os.path
    if not os.path.exists("/proc/meminfo"): print 1024
    with open("/proc/meminfo") as fh:
    line = fh.readline()
    if "MemTotal" in line and "kB" in line:
    m = re.search("\d+", line)
    if m:
    memory_kb = float(m.group()) * 0.7
    memory_mb = int(memory_kb / 1024)
    print memory_mb
    else:
    print 1024
    EOF

    memory_max_mb=$(python $memory_estimate_script)

    export JAVA_HOME=/opt/java
    export JAVA_OPTS="-Xms512m -Xmx"$memory_max_mb"m -XX:+UseParallelGC -Duser.timezone=Asia/Taipei -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "
    echo "JAVA_OPTS "$JAVA_OPTS