Effect CommunityEC
Effect Community•16mo ago•
4 replies
umami

Monitoring Memory Usage of an Effect

*This may be off-topic: *

šŸ‘‰ I want to monitor the memory usage of an Effect.

I plan to put that information as an annotation of the span of that Effect .
In this Effect, I yield other Effects that will query a db, do list comprehension, etc ...

My first guess is to use process.memoryUsage.

This is an POC using the Tracing documentation's code example.

const task = (
  name: string,
  delay: number,
  children: ReadonlyArray<Effect.Effect<void>> = [],
) =>
  Effect.gen(function* () {
    yield* Effect.log(name);
    yield* Effect.sleep(`${delay} millis`);
    for (const child of children) {
      yield* child;
    }
    yield* Effect.sleep(`${delay} millis`);
    yield* Effect.log(
      `Memory usage -> ${process.memoryUsage().heapUsed / 1_000_000}`,
    );
  }).pipe(
    Effect.tap(() =>
      Effect.annotateCurrentSpan(
        "memoryUsage",
        process.memoryUsage().heapUsed / 1_000_000,
      ),
    ),
    Effect.withSpan(name),
  );

ā“ Is this the most precise / correct method to monitor an Effect's memory usage ? How would you go about it ?
Explore the necessity of tracing in distributed systems beyond logs and metrics. Discover spans and traces, crucial for understanding request lifecycles. Learn to create, print, and annotate spans, and visualize traces for effective debugging and optimization.
Introduction to Tracing in Effect – Effect Docs
Was this page helpful?