[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6GXTH5KN7RGFW5DFVBH9HSH":3,"skill-same:01M6GXTH5KN7RGFW5DFVBH9HSH":76},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":34,"linkOnly":35,"markdownContent":36,"markdownBody":37,"frontMatter":38,"refName":39,"commitSha":40,"skillDirectory":41,"forksCount":42,"repositoryHtmlUrl":43,"repositoryHomepageUrl":6,"ownerHtmlUrl":44,"ownerBlogUrl":45,"ownerDescription":46,"updatedAt":47,"install":48,"resources":61},"01M6GXTH5KN7RGFW5DFVBH9HSH","cap-concurrency-for-expensive-endpoints",null,"Use when one expensive endpoint exhausts the shared pool and starves everything else — give it a dedicated bounded lane and its own connection pool.","jiayaoqijia\u002Fcryptoskill","jiayaoqijia","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1453879?v=4","01M6GMYTX7Q7S504VC6E756ENR","YQ","01M6GMYV1QKJ1CC75MTTGT9PR0",81,"MIT","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-cap-concurrency-for-expensive-endpoints\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-cap-concurrency-for-expensive-endpoints\u002FSKILL.md",[],[20,21,22,23,24,25,26,27,28,29,30,31,32,33],"concurrency","endpoints","cap","cap concurrency for expensive endpoints","for","lane","endpoint","use","shared","it","connection","pool","bounded","when","2026-11-10 10:12:30",false,"---\nname: cap-concurrency-for-expensive-endpoints\ndescription: Use when one expensive endpoint exhausts the shared pool and starves everything else — give it a dedicated bounded lane and its own connection pool.\n---\n\n# Cap concurrency for expensive endpoints\n\nA few expensive endpoints share the same connection pool and thread budget as cheap ones. Run concurrently, they consume every connection and starve health checks and fast reads. Give expensive work its own small, bounded lane.\n\n## Procedure\n\n1. Identify expensive endpoints by measured cost: p99 over 1s, or query rows\u002FCPU per call far above the mean. Cross-reference the endpoint with `pg_stat_statements` total time.\n2. Give each a dedicated concurrency limit, separate from the general request limiter:\n```python\nREPORT_SEM = asyncio.Semaphore(4)\nasync def report(req):\n    if not await acquire_now(REPORT_SEM):     # non-blocking try-acquire\n        raise HTTPException(429, \"report lane full\", headers={\"Retry-After\": \"5\"})\n    try:\n        ...\n    finally:\n        REPORT_SEM.release()                  # release on every path\n```\n3. Or use a bulkhead: a separate connection pool or worker pool for expensive work, so it can never take the general pool's connections:\n```python\nreport_engine = create_engine(url, pool_size=4, pool_timeout=2)\n```\n4. Return `429` with `Retry-After` when the lane is full, rather than queueing until everything times out.\n5. Move genuinely heavy work — exports, big reports — to a background job: return `202 Accepted` with a job id and let the client poll; do not hold an HTTP connection for 30s.\n6. Set a per-endpoint timeout shorter than the request budget so a runaway report is cancelled and releases its slot.\n7. Watch the lane's queue depth and the general pool's wait time; if expensive endpoints still starve the general pool, the bulkhead is not actually separate.\n\n## Pitfalls\n\n- A global rate limiter that does not distinguish endpoints, so cheap requests are throttled while expensive ones slip through elsewhere.\n- A semaphore acquired but not released on the error path, leaking slots until the lane is permanently full.\n- A bulkhead that shares the same underlying connection pool, so it is not a bulkhead at all.\n- `429` without `Retry-After`, so clients retry immediately and hold the lane saturated.\n- Streaming a 30s report through the request path instead of making it a job.\n- Setting the lane size above the database's useful concurrency, so the cap protects nothing.\n\n## Verification\n\n    hey -z 30s -c 50 http:\u002F\u002Flocalhost:8080\u002Freport &\n    hey -z 30s -c 50 http:\u002F\u002Flocalhost:8080\u002Fping\n    curl -s localhost:9090\u002Fmetrics | grep -E \"report_inflight|pool_wait_seconds\"\n    # pass: \u002Fping p99 unchanged, \u002Freport returns 429 past the cap, pool wait near zero\n\nReport the endpoint's concurrency cap and pool, the 429 behavior, and the p99 of a cheap endpoint while the expensive one is saturated.\n","# Cap concurrency for expensive endpoints\n\nA few expensive endpoints share the same connection pool and thread budget as cheap ones. Run concurrently, they consume every connection and starve health checks and fast reads. Give expensive work its own small, bounded lane.\n\n## Procedure\n\n1. Identify expensive endpoints by measured cost: p99 over 1s, or query rows\u002FCPU per call far above the mean. Cross-reference the endpoint with `pg_stat_statements` total time.\n2. Give each a dedicated concurrency limit, separate from the general request limiter:\n```python\nREPORT_SEM = asyncio.Semaphore(4)\nasync def report(req):\n    if not await acquire_now(REPORT_SEM):     # non-blocking try-acquire\n        raise HTTPException(429, \"report lane full\", headers={\"Retry-After\": \"5\"})\n    try:\n        ...\n    finally:\n        REPORT_SEM.release()                  # release on every path\n```\n3. Or use a bulkhead: a separate connection pool or worker pool for expensive work, so it can never take the general pool's connections:\n```python\nreport_engine = create_engine(url, pool_size=4, pool_timeout=2)\n```\n4. Return `429` with `Retry-After` when the lane is full, rather than queueing until everything times out.\n5. Move genuinely heavy work — exports, big reports — to a background job: return `202 Accepted` with a job id and let the client poll; do not hold an HTTP connection for 30s.\n6. Set a per-endpoint timeout shorter than the request budget so a runaway report is cancelled and releases its slot.\n7. Watch the lane's queue depth and the general pool's wait time; if expensive endpoints still starve the general pool, the bulkhead is not actually separate.\n\n## Pitfalls\n\n- A global rate limiter that does not distinguish endpoints, so cheap requests are throttled while expensive ones slip through elsewhere.\n- A semaphore acquired but not released on the error path, leaking slots until the lane is permanently full.\n- A bulkhead that shares the same underlying connection pool, so it is not a bulkhead at all.\n- `429` without `Retry-After`, so clients retry immediately and hold the lane saturated.\n- Streaming a 30s report through the request path instead of making it a job.\n- Setting the lane size above the database's useful concurrency, so the cap protects nothing.\n\n## Verification\n\n    hey -z 30s -c 50 http:\u002F\u002Flocalhost:8080\u002Freport &\n    hey -z 30s -c 50 http:\u002F\u002Flocalhost:8080\u002Fping\n    curl -s localhost:9090\u002Fmetrics | grep -E \"report_inflight|pool_wait_seconds\"\n    # pass: \u002Fping p99 unchanged, \u002Freport returns 429 past the cap, pool wait near zero\n\nReport the endpoint's concurrency cap and pool, the 429 behavior, and the p99 of a cheap endpoint while the expensive one is saturated.\n",{"name":5,"description":7},"main","3df1d0d67b30ff15236561f8c0f9f06d33f42dfd","skills\u002Fpayments\u002F0xklen-cap-concurrency-for-expensive-endpoints",17,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia","https:\u002F\u002Feth2030.com","Hardcore infra. Building @alt-research and applied cryptography.","2026-11-12 02:28:42",{"source":8,"skillName":5,"commands":49,"prompt":59,"zipAvailable":60},[50,53,56],{"tool":51,"command":52},"npx","npx skills add jiayaoqijia\u002Fcryptoskill --skill cap-concurrency-for-expensive-endpoints",{"tool":54,"command":55},"bunx","bunx skills add jiayaoqijia\u002Fcryptoskill --skill cap-concurrency-for-expensive-endpoints",{"tool":57,"command":58},"pnpm","pnpm dlx skills add jiayaoqijia\u002Fcryptoskill --skill cap-concurrency-for-expensive-endpoints","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-cap-concurrency-for-expensive-endpoints\u002FSKILL.md",true,[62,66,72],{"path":63,"resourceType":63,"resourceTypeDesc":64,"sizeBytes":65,"sourceHtmlUrl":16},"LICENSE","许可证",1063,{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},"SOURCE.md","REFERENCE","参考文档",365,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-cap-concurrency-for-expensive-endpoints\u002FSOURCE.md",{"path":73,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":74,"sourceHtmlUrl":75},"TRUST.auto.yaml",2217,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-cap-concurrency-for-expensive-endpoints\u002FTRUST.auto.yaml",[77,105,127,145,158,168],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":81,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":34},"01M712C436EQYE43342Q4E7GG1","recipe-performance","Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold\u002Fwarm\u002Fbackground-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout\u002Fpaint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fwallets\u002Fmetamask-official-recipe-performance\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fwallets\u002Fmetamask-official-recipe-performance\u002FSKILL.md",[],[85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104],"performance","recipe performance","recipe","mm","sentry","harness","app","deterministic","recipes","flow","cold","critical","analysis","tasks","react","browser","layout","screen","network","metamask",{"skillNo":106,"name":107,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":109,"licenseFileUrl":110,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":34},"01M70XT2F8A5CQZ81JBP98KSW3","mexc-spot-websocket","MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fmncrftfrcnm-mexc-spot-websocket\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fmncrftfrcnm-mexc-spot-websocket\u002FSKILL.md",[],[114,115,116,117,118,119,120,121,122,123,24,124,125,126],"mexc spot websocket","spot","websocket","api","workflows","public","listen","streams","depth","keys","api keys","maintenance","protobuf",{"skillNo":128,"name":129,"nameZh":6,"description":130,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":109,"licenseFileUrl":131,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":34},"01M70XT0MBXN3WZY1BKN0CPNKR","mexc-spot-rest","MEXC Spot REST workflows for public data, signed account requests, orders, wallet\u002Fadmin actions, and secure signing without exposing API keys.","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fmncrftfrcnm-mexc-spot-rest\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fmncrftfrcnm-mexc-spot-rest\u002FSKILL.md",[],[135,115,136,137,138,139,140,124,24,123,141,142,143,119,144,118,117],"mexc spot rest","REST","admin","signing","Wallet","requests","actions","secure","data","orders",{"skillNo":146,"name":147,"nameZh":6,"description":148,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":109,"licenseFileUrl":149,"sourceHtmlUrl":150,"categories":151,"keywords":152,"publishedAt":34},"01M70XSYSVZ2N0N91XCAR2CAK0","mexc-futures-websocket","MEXC Futures WebSocket workflows for public streams, private account\u002Forder\u002Fposition streams, ping\u002Fpong, subscriptions, and depth maintenance.","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fmncrftfrcnm-mexc-futures-websocket\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fmncrftfrcnm-mexc-futures-websocket\u002FSKILL.md",[],[153,154,116,155,156,125,24,157,122,121,119,118],"mexc futures websocket","futures","position","ping","subscriptions",{"skillNo":159,"name":160,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":161,"sourceHtmlUrl":162,"categories":163,"keywords":164,"publishedAt":34},"01M6H0ZWHVE5W04WG2DKQE2SQC","0xklen-version-and-refresh-sanctions-lists","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-version-and-refresh-sanctions-lists\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-version-and-refresh-sanctions-lists\u002FSKILL.md",[],[165,166,167],"refresh","0xklen version and refresh sanctions lists","version",{"skillNo":169,"name":170,"nameZh":6,"description":171,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":172,"sourceHtmlUrl":173,"categories":174,"keywords":175,"publishedAt":34},"01M6H0Z28Q3R8J0S799GJQWXM3","verify-tests-cover-changed-lines","Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-verify-tests-cover-changed-lines\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fpayments\u002F0xklen-verify-tests-cover-changed-lines\u002FSKILL.md",[],[176,177,178,179,180,181,182,27,183,184,185],"tests","cover","verify tests cover changed lines","verify","coverage","pr","exercise","patch","code","share"]