Skip to content

Commit

Permalink
add back in jitter logic to align with other lang
Browse files Browse the repository at this point in the history
  • Loading branch information
l0lawrence committed Aug 1, 2023
1 parent d3785fd commit 9b64952
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import functools
import time
import math
import random
import datetime
from datetime import timezone
from typing import Optional, Tuple, cast, List, TYPE_CHECKING, Any, Callable, Dict, Union, Iterator, Type
Expand Down Expand Up @@ -550,14 +552,14 @@ def create_receive_client(
link_properties = kwargs.pop("link_properties")

if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access
timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) # pylint: disable=protected-access
# open_receive_link_base_jitter_in_ms = 100
# open_recieve_link_buffer_in_ms = 20
# open_receive_link_buffer_threshold_in_ms = 1000
# jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms)
# timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random())
# if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms:
# timeout_in_ms -= open_recieve_link_buffer_in_ms
timeout_in_ms = receiver._max_wait_time * 1000 # pylint: disable=protected-access
open_receive_link_base_jitter_in_ms = 100
open_recieve_link_buffer_in_ms = 20
open_receive_link_buffer_threshold_in_ms = 1000
jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms)
timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random())
if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms:
timeout_in_ms -= open_recieve_link_buffer_in_ms

# If we have specified a client-side timeout, assure that it is encoded as an uint
link_properties[OPERATION_TIMEOUT] = amqp_uint_value(timeout_in_ms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import functools
from typing import TYPE_CHECKING, Optional, Any, Callable, Union, AsyncIterator, cast
import time
import math
import random

from ..._pyamqp import constants
from ..._pyamqp.message import BatchMessage
Expand Down Expand Up @@ -174,14 +176,14 @@ def create_receive_client_async(
link_properties = kwargs.pop("link_properties")

if receiver._session_id == NEXT_AVAILABLE_SESSION and receiver._max_wait_time: # pylint: disable=protected-access
timeout_in_ms = ((receiver._max_wait_time * 1000) - 100) # pylint: disable=protected-access
# open_receive_link_base_jitter_in_ms = 100
# open_recieve_link_buffer_in_ms = 20
# open_receive_link_buffer_threshold_in_ms = 1000
# jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms)
# timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random())
# if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms:
# timeout_in_ms -= open_recieve_link_buffer_in_ms
timeout_in_ms = receiver._max_wait_time * 1000 # pylint: disable=protected-access
open_receive_link_base_jitter_in_ms = 100
open_recieve_link_buffer_in_ms = 20
open_receive_link_buffer_threshold_in_ms = 1000
jitter_base_in_ms = min(timeout_in_ms * 0.01, open_receive_link_base_jitter_in_ms)
timeout_in_ms = math.floor(timeout_in_ms - jitter_base_in_ms * random.random())
if timeout_in_ms >= open_receive_link_buffer_threshold_in_ms:
timeout_in_ms -= open_recieve_link_buffer_in_ms

# If we have specified a client-side timeout, assure that it is encoded as an uint
link_properties[OPERATION_TIMEOUT] = amqp_uint_value(timeout_in_ms)
Expand Down

0 comments on commit 9b64952

Please sign in to comment.