Repository Public
1// Mesure les temps de réponse de l'API (à froid puis à chaud) et signale ce qui2// dépasse le seuil. Usage : node scripts/api-mesure.mjs [base] [seuil_ms]3// base défaut http://127.0.0.1:80914// seuil_ms défaut 10005const BASE = process.argv[2] ?? "http://127.0.0.1:8091";6const SEUIL = Number(process.argv[3] ?? 1000);78const UNITE = process.env.VP_UNITE ?? "";9const chemins = [10 "/api/version",11 "/api/search?q=1075%20chemin%20sainte-foy",12 "/api/search?q=rue%20saint-denis%20montreal&limit=20",13 UNITE && `/api/units/${UNITE}`,14 UNITE && `/api/estimate?id=${UNITE}`,15 "/api/nearby?lat=45.5421&lng=-73.6646&halfLat=0.02&halfLng=0.03&limit=1500",16 "/api/map?layer=units&bbox=-73.60,45.50,-73.55,45.53&limit=1500",17 "/api/map?layer=sales&bbox=-73.60,45.50,-73.55,45.53",18 "/api/map?layer=listings&bbox=-73.70,45.45,-73.50,45.60",19 "/api/ventes",20 "/api/ventes?q=Montr%C3%A9al&periode=365&type=condo&page=3",21 "/api/ventes?periode=all&min=1000000&page=40",22 "/api/ventes/overview",23 "/api/municipalites",24 "/api/municipalites?q=saint-j",25 "/api/municipalites/montreal",26 "/api/municipalites/quebec",27 "/api/municipalites/gatineau",28 "/api/indice",29 "/api/indice?type=condo",30 "/api/stats",31 "/api/stats/dashboard",32 "/api/stats/marche",33 "/api/stats/catalog",34 "/api/avendre",35 "/api/avendre?q=laval&group=maison&sort=deal&eval=1",36 "/api/cost/overview",37 "/api/cost/locations",38 "/api/cost/assemblies",39 UNITE && `/api/report?id=${UNITE}`,40 UNITE && `/api/report/pro?id=${UNITE}`,41 "/api/stats/report?mode=synthese",42 "/",43 "/ventes",44 "/municipalites",45 "/municipalite/montreal",46 "/stats",47 "/a-vendre",48 "/cout",49 UNITE && `/estimation/${UNITE}`,50].filter(Boolean);5152async function mesurer(chemin) {53 const t0 = performance.now();54 const r = await fetch(BASE + chemin, { headers: { accept: "*/*" } });55 const corps = await r.arrayBuffer();56 return { code: r.status, ms: Math.round(performance.now() - t0), octets: corps.byteLength };57}5859let lents = 0;60console.log("code froid chaud taille chemin");61for (const c of chemins) {62 try {63 const froid = await mesurer(c);64 const a = await mesurer(c);65 const b = await mesurer(c);66 const chaud = Math.min(a.ms, b.ms);67 const marque = chaud > SEUIL ? " << LENT" : froid.code >= 400 ? " << ERREUR" : "";68 if (chaud > SEUIL) lents++;69 console.log(70 `${String(froid.code).padEnd(4)} ${String(froid.ms).padStart(6)} ${String(chaud).padStart(6)} ${String(Math.round(froid.octets / 1024) + " k").padStart(8)} ${c}${marque}`71 );72 } catch (e) {73 console.log(`ERR ${c} ${e.message}`);74 }75}76console.log(lents ? `\n${lents} route(s) au-dessus de ${SEUIL} ms à chaud` : `\nTout est sous ${SEUIL} ms à chaud`);77