Skip to content

Commit

Permalink
Merge branch 'hotfix/1.2.5' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
agates committed Aug 10, 2022
2 parents 8ad13fd + 520affe commit d6e67a7
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 238 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pypi_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ jobs:
- name: Build and publish to pypi (3.10)
uses: JRubics/[email protected]
with:
python_version: "3.10.2"
python_version: "3.10.4"
ignore_dev_requirements: "yes"
pypi_token: ${{ secrets.PYPI_TOKEN }}
extra_build_dependency_packages: "capnproto libzmq3-dev"
- name: Build and publish to pypi (3.9)
uses: JRubics/[email protected]
with:
python_version: "3.9.10"
python_version: "3.9.13"
build_format: wheel
ignore_dev_requirements: "yes"
pypi_token: ${{ secrets.PYPI_TOKEN }}
extra_build_dependency_packages: "capnproto libzmq3-dev"
- name: Build and publish to pypi (3.8)
uses: JRubics/[email protected]
with:
python_version: "3.8.12"
python_version: "3.8.13"
build_format: wheel
ignore_dev_requirements: "yes"
pypi_token: ${{ secrets.PYPI_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/pypy:3.8-bullseye AS compile
FROM docker.io/python:3.10-bullseye AS compile

ENV PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
Expand Down Expand Up @@ -27,7 +27,7 @@ RUN pip install --upgrade pip \
&& poetry config virtualenvs.in-project true \
&& poetry install --no-root --no-dev --no-interaction --no-ansi

FROM docker.io/pypy:3.8-slim-bullseye AS app
FROM docker.io/python:3.10-slim-bullseye AS app

ENV PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
Expand Down
107 changes: 107 additions & 0 deletions examples/memory_profile/long_running_zmq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import asyncio
import linecache
import logging
import os

try:
import tracemalloc
except ModuleNotFoundError:
tracemalloc = False
import uuid
from random import randint
from platform import python_version as pv, python_implementation as pi
from timeit import default_timer as timer

import zmq
import zmq.asyncio

from podping_hivewriter.constants import LIVETEST_OPERATION_ID
from podping_hivewriter.models.medium import Medium
from podping_hivewriter.models.reason import Reason
from podping_hivewriter.podping_hivewriter import PodpingHivewriter
from podping_hivewriter.podping_settings_manager import PodpingSettingsManager


def display_top(snapshot, key_type="lineno", limit=3):
snapshot = snapshot.filter_traces(
(
tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
tracemalloc.Filter(False, "<unknown>"),
)
)
top_stats = snapshot.statistics(key_type)

logging.info("Top %s lines" % limit)
for index, stat in enumerate(top_stats[:limit], 1):
frame = stat.traceback[0]
# replace "/path/to/module/file.py" with "module/file.py"
filename = os.sep.join(frame.filename.split(os.sep)[-2:])
logging.info(
"#%s: %s:%s: %.1f KiB" % (index, filename, frame.lineno, stat.size / 1024)
)
line = linecache.getline(frame.filename, frame.lineno).strip()
if line:
logging.info(" %s" % line)

other = top_stats[limit:]
if other:
size = sum(stat.size for stat in other)
logging.info("%s other: %.1f KiB" % (len(other), size / 1024))
total = sum(stat.size for stat in top_stats)
logging.info("Total allocated size: %.1f KiB" % (total / 1024))


async def endless_send_loop(event_loop):
context = zmq.asyncio.Context()
socket = context.socket(zmq.REQ, io_loop=event_loop)
socket.connect(f"tcp://{host}:{port}")

test_name = "long_running_zmq"
python_version = pv()
python_implementation = pi()
start_time = timer()

while True:
session_uuid = uuid.uuid4()
session_uuid_str = str(session_uuid)

num_iris = randint(1, 10)

for i in range(num_iris):
await socket.send_string(
f"https://example.com?t={test_name}&i={i}&v={python_version}&pi={python_implementation}&s={session_uuid_str}"
)
response = await socket.recv_string()
assert response == "OK"

if tracemalloc and (timer() - start_time) >= 60:
snapshot = tracemalloc.take_snapshot()
display_top(snapshot)
start_time = timer()
await asyncio.sleep(3)


if __name__ == "__main__":
if tracemalloc:
tracemalloc.start()
loop = asyncio.get_event_loop()
logging.getLogger().setLevel(level=logging.INFO)
settings_manager = PodpingSettingsManager()

host = "127.0.0.1"
port = 9979
podping_hivewriter = PodpingHivewriter(
os.environ["PODPING_HIVE_ACCOUNT"],
[os.environ["PODPING_HIVE_POSTING_KEY"]],
settings_manager,
medium=Medium.podcast,
reason=Reason.update,
listen_ip=host,
listen_port=port,
resource_test=True,
operation_id=LIVETEST_OPERATION_ID,
)
loop.run_until_complete(podping_hivewriter.wait_startup())
loop.run_until_complete(endless_send_loop(loop))

podping_hivewriter.close()
2 changes: 1 addition & 1 deletion install-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apt-get update
apt-get -y upgrade

# Install application dependencies
apt-get -y install --no-install-recommends capnproto libffi7 libssl1.1 libzmq5 zlib1g
apt-get -y install --no-install-recommends capnproto libffi7 libssl1.1 libzmq5 zlib1g gcc libstdc++-10-dev

# Delete cached files we don't need anymore (note that if you're
# using official Docker images for Debian or Ubuntu, this happens
Expand Down
Loading

0 comments on commit d6e67a7

Please sign in to comment.