Julian IncrEdelman
Julian IncrEdelman
PPrisma
Created by Julian IncrEdelman on 11/18/2024 in #help-and-questions
Raw SQL returns ~5x slower than CLI / `pg` package
I have a query that returns 170k rows of two 4-byte integer (so ~1.5MB total). When I run this on the CLI (pgsql), I get a ~500ms runtime. Using queryRawUnsafe or queryRaw. the query is 2-3 secs. I even hooked up the pg package and confirmed it is around ~500ms. Whu could Prisma be adding this overhead? Is there anything I could do to minimize it? Some other info: - I am running this in a serialized transaction; I see no perf difference when without a transaction - the query basically looks like this:
SELECT
image_id,
label_id
FROM labels_images li
INNER JOIN images i
ON i.id = li.image_id
WHERE i.customer_id = <number>
SELECT
image_id,
label_id
FROM labels_images li
INNER JOIN images i
ON i.id = li.image_id
WHERE i.customer_id = <number>
(where image_id and label_id are 4 byte ints) - but, again, running this same command via pg or psql is ~5x faster than the Prisma options...
7 replies
PPrisma
Created by Julian IncrEdelman on 11/17/2024 in #help-and-questions
Tracing / OTEL only works with manual active spans.
I have just spent a few hours pulling my hair out to no avail. I tried to boil things down simply: Ths code does not submit any traces to the console nor Jaeger UI:
import { OTLPTraceExporter } from "
// Configure the trace provider
const provider = new NodeTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: "example application",
[SEMRESATTRS_SERVICE_VERSION]: "0.0.1",
}),
});

// Configure how spans are processed and exported. In this case we're sending spans
// as we receive them to an OTLP-compatible collector (e.g. Jaeger).
provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));

// Register your auto-instrumentors
registerInstrumentations({
tracerProvider: provider,
instrumentations: [new PrismaInstrumentation({ middleware: true })],
});

// Register the provider globally
provider.register();

import { PrismaClient } from "@prisma/client";

async function main() {
const data = await new PrismaClient().user.findFirst();
console.log("data", data);
}
main();
import { OTLPTraceExporter } from "
// Configure the trace provider
const provider = new NodeTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: "example application",
[SEMRESATTRS_SERVICE_VERSION]: "0.0.1",
}),
});

// Configure how spans are processed and exported. In this case we're sending spans
// as we receive them to an OTLP-compatible collector (e.g. Jaeger).
provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));

// Register your auto-instrumentors
registerInstrumentations({
tracerProvider: provider,
instrumentations: [new PrismaInstrumentation({ middleware: true })],
});

// Register the provider globally
provider.register();

import { PrismaClient } from "@prisma/client";

async function main() {
const data = await new PrismaClient().user.findFirst();
console.log("data", data);
}
main();
Confusingly, if I send a manual trace, it shows up in the Jager UI. This indicates to me that something about the Prisma configuration is not working (I have followed the steps in the documentation... (1) enabled tracing (2) placed init before any code (3) run npx prisma generate`)
const tracer = trace.getTracer("Application");

tracer.startActiveSpan("testSpan", async (span) => {
const data = await new PrismaClient().user.findFirst();
console.log("data", data);
span.end();
});
const tracer = trace.getTracer("Application");

tracer.startActiveSpan("testSpan", async (span) => {
const data = await new PrismaClient().user.findFirst();
console.log("data", data);
span.end();
});
7 replies