Skip to content

Commit

Permalink
memory usage logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sstill88 committed Jan 2, 2025
1 parent 12a35bf commit 667e450
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cerulean_cloud/cloud_run_orchestrator/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import httpx
import numpy as np
import psutil
import rasterio
import skimage
from rasterio.enums import Resampling
Expand Down Expand Up @@ -83,6 +84,17 @@ def __init__(
layers, self.sceneid, tileset_envelope_bounds, image_hw_pixels
)

# Log memory usage and aux_datasets size
self.logger.info(
structured_log(
"MEMORY USAGE 1",
severity="INFO",
scene_id=self.sceneid,
aux_datasets_size_mb=sys.getsizeof(self.aux_datasets) / (1024**2),
memory_usage_mb=psutil.Process().memory_info().rss / (1024**2),
)
)

async def fetch_and_process_image(
self, tile_bounds, rescale=(0, 255), num_channels=1
):
Expand Down Expand Up @@ -303,6 +315,15 @@ async def run_parallel_inference(self, tileset):
# If asyncio.gather tasks fail, raise ValueError
raise ValueError(f"Failed to gather inference: {e}")
finally:
self.logger.info(
structured_log(
"MEMORY USAGE 2",
severity="INFO",
scene_id=self.sceneid,
aux_datasets_size_mb=sys.getsizeof(self.aux_datasets) / (1024**2),
memory_usage_mb=psutil.Process().memory_info().rss / (1024**2),
)
)
# Cleanup: close and delete aux_datasets
if self.aux_datasets:
del self.aux_datasets
Expand Down

0 comments on commit 667e450

Please sign in to comment.