Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add objectgraph logging #2609

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tilecloud_chain/generate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Generate the tiles, generate the queue, ..."""

import gc
import logging
import os
import random
Expand All @@ -13,6 +14,7 @@
from typing import IO, cast

import boto3
import objgraph
import prometheus_client
import tilecloud.filter.error
from tilecloud import Tile, TileCoord, TileStore
Expand Down Expand Up @@ -44,6 +46,21 @@
_LOGGER = logging.getLogger(__name__)


def _objgraph(tile: Tile) -> Tile:
"""Log the objgraph."""
for generation in range(3):
gc.collect(generation)
values = [
f"{name}: {number} {diff}"
for name, number, diff in objgraph.growth(
limit=int(os.environ.get("TILECLOUD_CHAIN_OBJGRAPH_LIMIT", "10"))
)
]
if values:
_LOGGER.debug("Objgraph growth in queue:\n%s", "\n".join(values))
return tile


class LogTilesContext:
"""Logging tile context."""

Expand Down Expand Up @@ -111,6 +128,9 @@ def gene(self, layer_name: str | None = None) -> None:
if self._options.role != "slave" or self._options.tiles:
self._generate_queue(layer_name)

if os.environ.get("TILECLOUD_CHAIN_OBJGRAPH_GENE", "0").lower() in ("1", "true", "on"):
self._gene.imap(_objgraph)

self.generate_consume()
self.generate_resume(layer_name)

Expand Down
18 changes: 18 additions & 0 deletions tilecloud_chain/store/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import gc
import io
import logging
import multiprocessing
Expand All @@ -38,6 +39,7 @@
from datetime import datetime, timedelta
from typing import Any, cast

import objgraph
import sqlalchemy
import sqlalchemy.sql.functions
from prometheus_client import Counter, Gauge, Summary
Expand Down Expand Up @@ -525,6 +527,22 @@ def list(self) -> Iterator[Tile]:
continue
job_id = self.jobs.pop(config_filename)
try:
if os.environ.get("TILECLOUD_CHAIN_OBJGRAPH_POSTGRESQL", "0").lower() in (
"1",
"true",
"on",
):
for generation in range(3):
gc.collect(generation)
values = [
f"{name}: {number} {diff}"
for name, number, diff in objgraph.growth(
limit=int(os.environ.get("TILECLOUD_CHAIN_OBJGRAPH_LIMIT", "10"))
)
]
if values:
_LOGGER.debug("Objgraph growth in postgresql:\n%s", "\n".join(values))

with self.SessionMaker() as session:
sqlalchemy_tile = (
session.query(Queue)
Expand Down
Loading