CtrlK
BlogDocsLog inGet started
Tessl Logo

simon/skills

Auto-generated tile from GitHub (10 skills)

92

1.16x
Quality

94%

Does it follow best practices?

Impact

92%

1.16x

Average score across 44 eval scenarios

SecuritybySnyk

Advisory

Suggest reviewing before use

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-39/

Fix High-Latency Bottleneck in Customer Verification Service

Problem Description

A SaaS company runs a customer verification service that handles thousands of incoming requests per minute. Each request involves:

  1. Resolving the customer's server hostname to verify their infrastructure is reachable
  2. Reading a large shared configuration file (~20MB) that maps customer IDs to their settings
  3. Processing the verification logic

After load testing, the operations team discovered that p99 request latency spikes to over 500ms during peak load, even though each individual operation appears fast in isolation. The initial hypothesis is that the service is encountering a hidden resource contention problem — but they can't see it from regular application logs.

A senior engineer suspects the issue is related to how Node.js handles blocking operations internally. Your task is to analyze the provided service code, diagnose the root cause of the latency spikes, produce a corrected version of the service, and provide a startup script and monitoring code so the team can observe the fix working.

Output Specification

Produce the following files:

  • fixed-service.js — A corrected version of inputs/service.js that addresses the root cause(s) of the thread pool saturation
  • start.sh — A shell script to start the fixed service with the correct environment configuration for a production deployment on an 8-core machine
  • diagnosis.md — An explanation of what caused the latency spikes and how the fix addresses it
  • monitoring.js — A self-contained Node.js script that measures and reports event loop health metrics relevant to detecting the bottleneck described in the diagnosis

Input Files

The following file is provided as input. Extract it before beginning.

=============== FILE: inputs/service.js =============== 'use strict';

const http = require('node:http'); const dns = require('node:dns'); const fs = require('node:fs/promises'); const path = require('node:path');

// Path to the shared configuration file const CONFIG_FILE = path.join(__dirname, 'customer-config.json');

// Cache: populated once on startup, then used per-request let configCache = null;

async function loadConfig() { // Read entire config into memory on each cache miss const raw = await fs.readFile(CONFIG_FILE, 'utf8'); configCache = JSON.parse(raw); }

async function resolveCustomerHost(hostname) { // Resolve hostname to IP for verification return new Promise((resolve, reject) => { dns.lookup(hostname, (err, address) => { if (err) return reject(err); resolve(address); }); }); }

async function handleRequest(req, res) { try { // Ensure config is loaded if (!configCache) { await loadConfig(); }

// Parse customer info from request
const url = new URL(req.url, `http://${req.headers.host}`);
const customerId = url.searchParams.get('customer_id');
const hostname = url.searchParams.get('hostname') || 'example.com';

// Resolve hostname for every request
const ip = await resolveCustomerHost(hostname);

// Look up customer in config
const customerConfig = configCache?.[customerId];
if (!customerConfig) {
  res.writeHead(404, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ error: 'Customer not found' }));
  return;
}

// Simulate verification
const verified = customerConfig.allowed_ips?.includes(ip) ?? false;

res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
  customer_id: customerId,
  hostname,
  resolved_ip: ip,
  verified
}));

} catch (err) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: err.message })); } }

const server = http.createServer(handleRequest);

// Attempt to tune thread pool at runtime (done before starting server) process.env.UV_THREADPOOL_SIZE = 8;

server.listen(3000, () => { console.log('Customer verification service listening on port 3000'); });

evals

README.md

tile.json