관리-도구
편집 파일: adjust.cpython-311.pyc
� �Cgs � � � d dl Z d dlZd dlmZmZ ddlmZ ddlmZ ddl m Z mZmZm Z mZ ddlmZ ddlmZ dd lmZ G d � d� � Z G d� d � � ZdS )� N)�Any�Callable� )� bootstrap_gen)�logger)�AdjustStepData�empty_stats�empty_usage�GetNormalLimits�InvalidStateError)�OverloadCheckResult)�LvesTracker)�LveStateManagerc �B � e Zd ZdZdeddfd�Zdedefd�Zdedefd �ZdS ) �StepCalculator�2 �overload_threshold�returnNc �0 � d| _ d| _ || _ d S )Nr )�_last_enable_step�_last_disable_step�_overload_threshold)�selfr s ��/builddir/build/BUILDROOT/lve-stats-4.2.10-1.el8.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/plugins/generic/burster/adjust.py�__init__zStepCalculator.__init__ s � �!"���"#���#5�� � � � �server_loadc � � d| _ t | j dz | j � � }t j d| j z | j z |z | j z � � }t t |d� � | j � � }t ||� � }|| _ |S )a� Get current step size We start with 1 and increase step size by 1 on each iteration. Step size is bounded by two factors: 1. MAX_STEP 2. descending linear function (y = k * x + b) depending on sever_load: step_size = -1 * MAX_STEP / overload_threshold * sever_load + MAX_STEP :param float sever_load: server load estimation (from 0 to 1) :return int: step size r r ���)r �minr �MAX_STEP�math�ceilr �max)r r �next_step_size�upper_bound� step_sizes r �get_enable_stepzStepCalculator.get_enable_step! s� � � #$����T�3�a�7���G�G�� �i��T�]� 2�T�5M� M�P[� [�^b�^k� k�l�l���#�k�1�-�-�t�}�=�=�����4�4� �!*����r � lves_countc �t � d| _ t t | j dz d� � |� � | _ | j S )Nr � r )r r r$ r )r r) s r �get_disable_stepzStepCalculator.get_disable_step: s7 � �!"���"%�c�$�*A�A�*E�q�&I�&I�:�"V�"V����&�&r ) �__name__� __module__�__qualname__r! �floatr �intr( r, � r r r r s � � � � � ��H�6�5� 6�T� 6� 6� 6� 6� �5� �S� � � � �2'�3� '�3� '� '� '� '� '� 'r r c � � e Zd Z d dedededeg ef deddfd �Z d e defd�Ze dedededeg ef def d�� � ZdS )�AdjusterT�lves_tracker�get_normal_limits�step_calculator�is_server_overloaded� fail_fastr Nc �\ � | � |||||�� � j | _ d | _ d S )N)r5 r7 r6 r8 r9 )�_create_algorithm_gen�send�_step�_step_exception)r r5 r6 r7 r8 r9 s r r zAdjuster.__init__A sG � � �/�/�%�+�/�!5�� 0� � � � � � 26����r �adjust_step_datac �` � | � |� � | j �| j d c}| _ |�d S �N)r= r>