apache-ignite

Форк
0
161 строка · 4.9 Кб
1
# Licensed to the Apache Software Foundation (ASF) under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#    http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
"""
17
This module contains JVM utilities.
18
"""
19

20
from ignitetest.services.utils.decorators import memoize
21

22
DEFAULT_HEAP = "768M"
23

24
JVM_PARAMS_GC_G1 = "-XX:+UseG1GC -XX:MaxGCPauseMillis=100 " \
25
                   "-XX:ConcGCThreads=$(((`nproc`/3)>1?(`nproc`/3):1)) " \
26
                   "-XX:ParallelGCThreads=$(((`nproc`*3/4)>1?(`nproc`*3/4):1)) "
27

28
JVM_PARAMS_GENERIC = "-server -XX:+DisableExplicitGC -XX:+AlwaysPreTouch " \
29
                     "-XX:+ParallelRefProcEnabled -XX:+DoEscapeAnalysis " \
30
                     "-XX:+OptimizeStringConcat -XX:+UseStringDeduplication"
31

32

33
def create_jvm_settings(heap_size=DEFAULT_HEAP, gc_settings=JVM_PARAMS_GC_G1, generic_params=JVM_PARAMS_GENERIC,
34
                        gc_dump_path=None, oom_path=None, vm_error_path=None):
35
    """
36
    Provides settings string for JVM process.
37
    param opts: JVM options to merge. Adds new or rewrites default values. Can be list or string.
38
    """
39
    gc_dump = ""
40
    if gc_dump_path:
41
        gc_dump = "-verbose:gc -Xloggc:" + gc_dump_path
42

43
    out_of_mem_dump = ""
44
    if oom_path:
45
        out_of_mem_dump = "-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=" + oom_path
46

47
    vm_error_dump = ""
48
    if vm_error_path:
49
        vm_error_dump = "-XX:ErrorFile=" + vm_error_path
50

51
    as_string = f"-Xmx{heap_size} -Xms{heap_size} {gc_settings} {gc_dump} " \
52
                f"{out_of_mem_dump} {vm_error_dump} {generic_params}".strip()
53

54
    return as_string.split()
55

56

57
def merge_jvm_settings(src_settings, additionals):
58
    """
59
    Merges two JVM settings.
60
    :param src_settings: base settings. Can be list or string.
61
    :param additionals: params to add to or overwrite in src_settings. Can be list or string.
62
    :return merged JVM settings. By default as string.
63
    """
64
    mapped = _to_map(src_settings)
65

66
    mapped.update(_to_map(additionals))
67

68
    _remove_duplicates(mapped)
69

70
    listed = []
71
    for param, value in mapped.items():
72
        if value:
73
            listed.append(f"{param}={value}")
74
        else:
75
            listed.append(param)
76

77
    return listed
78

79

80
def java_major_version(version):
81
    """
82
    :param version: Full java version
83
    :return: Java major version
84
    """
85
    if version:
86
        version = version.split('.')
87

88
        return int(version[1]) if version[0] == '1' else int(version[0])
89

90
    return -1
91

92

93
def java_version(node):
94
    """
95
    :param node: Ducktape cluster node
96
    :return: java version
97
    """
98
    cmd = r"java -version 2>&1 | awk -F[\"\-] '/version/ {print $2}'"
99

100
    raw_version = list(node.account.ssh_capture(cmd, allow_fail=False))
101

102
    return raw_version[0].strip() if raw_version else ''
103

104

105
def _to_map(params):
106
    """"""
107
    assert isinstance(params, (str, list)), "JVM params an be string or list only."
108

109
    if isinstance(params, str):
110
        params = params.split()
111

112
    mapped = {}
113

114
    for elem in params:
115
        param_val = elem.split(sep="=", maxsplit=1)
116
        mapped[param_val[0]] = param_val[1] if len(param_val) > 1 else None
117

118
    return mapped
119

120

121
def _remove_duplicates(params: dict):
122
    """Removes specific duplicates"""
123
    duplicates = {"-Xmx": False, "-Xms": False, "-Xss": False, "-Xmn": False}
124

125
    for param_key in reversed(list(params.keys())):
126
        for dup_key, _ in duplicates.items():
127
            if param_key.startswith(dup_key):
128
                if duplicates[dup_key]:
129
                    del params[param_key]
130
                else:
131
                    duplicates[dup_key] = True
132

133

134
class JvmProcessMixin:
135
    """
136
    Mixin to work with JVM processes
137
    """
138

139
    @staticmethod
140
    def pids(node, java_class):
141
        """
142
        Return pids of jvm processes running this java class on service node.
143
        :param node: Service node.
144
        :param java_class: Java class name
145
        :return: List of service's pids.
146
        """
147
        cmd = "ps -C java -wwo pid,args | grep '%s' | awk -F' ' '{print $1}'" % java_class
148

149
        return [int(pid) for pid in node.account.ssh_capture(cmd, allow_fail=True)]
150

151

152
class JvmVersionMixin:
153
    """
154
    Mixin to get java version on node.
155
    """
156
    @memoize
157
    def java_version(self):
158
        """
159
        :return: Full java version of service.
160
        """
161
        return java_version(self.nodes[0])
162

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.