Skip to content

Commit

Permalink
Merge pull request #2610 from camptocamp/backport/2609-to-1.22
Browse files Browse the repository at this point in the history
[Backport 1.22] Add objectgraph logging
  • Loading branch information
sbrunner authored Nov 22, 2024
2 parents 3be141e + 9217d90 commit ae7bd67
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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

0 comments on commit ae7bd67

Please sign in to comment.