Skip to content

Commit

Permalink
PubNub SDK v4.5.3 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Aug 10, 2020
1 parent a252904 commit cd4f759
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 51 deletions.
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,3 @@ _trial_temp

# jupyter dev notebook
PubNubTwisted.ipynb

.travis/README.md

.travis/scripts

deployment_keys
deployment_keys-private
deployment_keys.tar
8 changes: 7 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
name: python
version: 4.5.2
version: 4.5.3
schema: 1
scm: github.com/pubnub/python
changelog:
- version: v4.5.3
date: Aug 10, 2020
changes:
-
text: "Allocating separate thread that basically waits certain amount of time to clean telemetry data is a waste of memory/OS data strucutres. Clening mentioned data can be incorporated into regular logic."
type: improvement
- version: v4.5.2
date: May 29, 2020
changes:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [v4.5.3](https://github.com/pubnub/python/releases/tag/v4.5.3)

[Full Changelog](https://github.com/pubnub/python/compare/v4.5.2...v4.5.3)

- ⭐️️ Allocating separate thread that basically waits certain amount of time to clean telemetry data is a waste of memory/OS data strucutres. Clening mentioned data can be incorporated into regular logic.

## [v4.5.2](https://github.com/pubnub/python/releases/tag/v4.5.2)

[Full Changelog](https://github.com/pubnub/python/compare/v4.5.1...v4.5.2)
Expand Down
19 changes: 9 additions & 10 deletions pubnub/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __init__(self, pubnub_instance):

self._subscription_state = StateManager()
self._listener_manager = ListenerManager(self._pubnub)
self._timetoken = int(0)
self._timetoken = 0
self._region = None

self._should_stop = False
Expand Down Expand Up @@ -395,19 +395,18 @@ def operation_latencies(self):

endpoint_average_latency = self.average_latency_from_data(endpoint_latencies)

if (endpoint_average_latency > 0):
if endpoint_average_latency > 0:
operation_latencies[latency_key] = endpoint_average_latency

return operation_latencies

def clean_up_telemetry_data(self):
current_timestamp = time.time()

copy_latencies = copy.deepcopy(dict(self.latencies))
copy_latencies = copy.deepcopy(self.latencies)

for endpoint_name, endpoint_latencies in copy_latencies.items():
for latency_information in list(endpoint_latencies):
if current_timestamp - latency_information['d'] > self.MAXIMUM_LATENCY_DATA_AGE:
for latency_information in endpoint_latencies:
if current_timestamp - latency_information["timestamp"] > self.MAXIMUM_LATENCY_DATA_AGE:
self.latencies[endpoint_name].remove(latency_information)

if len(self.latencies[endpoint_name]) == 0:
Expand All @@ -423,8 +422,8 @@ def store_latency(self, latency, operation_type):
self.latencies[endpoint_name] = []

latency_entry = {
'd': store_timestamp,
'l': latency,
"timestamp": store_timestamp,
"latency": latency,
}

self.latencies[endpoint_name].append(latency_entry)
Expand All @@ -433,8 +432,8 @@ def store_latency(self, latency, operation_type):
def average_latency_from_data(endpoint_latencies):
total_latency = 0

for k in endpoint_latencies:
total_latency += k['l']
for latency_data in endpoint_latencies:
total_latency += latency_data['latency']

return total_latency / len(endpoint_latencies)

Expand Down
13 changes: 2 additions & 11 deletions pubnub/pubnub.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,6 @@ def reset(self):


class NativeTelemetryManager(TelemetryManager): # pylint: disable=W0612
def __init__(self):
TelemetryManager.__init__(self)
self._timer = NativePeriodicCallback(
self._start_clean_up_timer,
self.CLEAN_UP_INTERVAL * self.CLEAN_UP_INTERVAL_MULTIPLIER)
self._timer.start()

def _start_clean_up_timer(self):
def store_latency(self, latency, operation_type):
super(NativeTelemetryManager, self).store_latency(latency, operation_type)
self.clean_up_telemetry_data()

def _stop_clean_up_timer(self):
self._timer.stop()
2 changes: 1 addition & 1 deletion pubnub/pubnub_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

class PubNubCore:
"""A base class for PubNub Python API implementations"""
SDK_VERSION = "4.5.2"
SDK_VERSION = "4.5.3"
SDK_NAME = "PubNub-Python"

TIMESTAMP_DIVIDER = 1000
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='pubnub',
version='4.5.2',
version='4.5.3',
description='PubNub Real-time push service in the cloud',
author='PubNub',
author_email='support@pubnub.com',
Expand Down
40 changes: 26 additions & 14 deletions tests/functional/test_telemetry_manager.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import unittest
import time

from pubnub.managers import TelemetryManager
from pubnub.pubnub import NativeTelemetryManager
from pubnub.enums import PNOperationType


class TestTelemetryManager(unittest.TestCase): # pylint: disable=W0612
@classmethod
def test_clean_up(cls):
manager = TelemetryManager()
manager.MAXIMUM_LATENCY_DATA_AGE = 1
def test_cleaning_up_latency_data():
manager = TelemetryManager()
manager.MAXIMUM_LATENCY_DATA_AGE = 1

for i in range(0, 10):
manager.store_latency(i, PNOperationType.PNPublishOperation)
for i in range(0, 10):
manager.store_latency(i, PNOperationType.PNPublishOperation)

# await for store timestamp expired
time.sleep(2)
# await for store timestamp expired
time.sleep(2)

manager.clean_up_telemetry_data()
print(manager.latencies)
manager.clean_up_telemetry_data()
print(manager.latencies)

if not 0 == len(manager.operation_latencies()):
raise AssertionError()
assert len(manager.operation_latencies()) == 0


def test_native_telemetry_cleanup():
manager = NativeTelemetryManager()
manager.MAXIMUM_LATENCY_DATA_AGE = 1

for i in range(1, 10):
manager.store_latency(i, PNOperationType.PNPublishOperation)

time.sleep(2)

for i in range(1, 10): # Latency = 0 is not being stored!
manager.store_latency(i, PNOperationType.PNPublishOperation)

assert len(manager.latencies["pub"]) == 9
10 changes: 5 additions & 5 deletions tests/unit/test_telemetry_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
def test_average_latency():
manager = TelemetryManager()
endpointLatencies = [
{"d": 100, "l": 10},
{"d": 100, "l": 20},
{"d": 100, "l": 30},
{"d": 100, "l": 40},
{"d": 100, "l": 50},
{"timestamp": 100, "latency": 10},
{"timestamp": 100, "latency": 20},
{"timestamp": 100, "latency": 30},
{"timestamp": 100, "latency": 40},
{"timestamp": 100, "latency": 50},
]

averageLatency = manager.average_latency_from_data(endpointLatencies)
Expand Down

0 comments on commit cd4f759

Please sign in to comment.