fix(tools): throttle ripgrep CPU usage with thread limits and concurrency control
- Add --threads=4 flag to all rg invocations (grep and glob) - Add global semaphore limiting concurrent rg processes to 2 - Reduce grep timeout from 300s to 60s (matches tool description) - Reduce max output from 10MB to 256KB (prevents excessive memory usage) - Add output_mode parameter (content/files_with_matches/count) - Add head_limit parameter for incremental result fetching Closes #2008 Ref: #674, #1722
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Simple counting semaphore to limit concurrent process execution.
|
||||
* Used to prevent multiple ripgrep processes from saturating CPU.
|
||||
*/
|
||||
export class Semaphore {
|
||||
private queue: (() => void)[] = []
|
||||
private running = 0
|
||||
|
||||
constructor(private readonly max: number) {}
|
||||
|
||||
async acquire(): Promise<void> {
|
||||
if (this.running < this.max) {
|
||||
this.running++
|
||||
return
|
||||
}
|
||||
return new Promise<void>((resolve) => {
|
||||
this.queue.push(() => {
|
||||
this.running++
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
release(): void {
|
||||
this.running--
|
||||
const next = this.queue.shift()
|
||||
if (next) next()
|
||||
}
|
||||
}
|
||||
|
||||
/** Global semaphore limiting concurrent ripgrep processes to 2 */
|
||||
export const rgSemaphore = new Semaphore(2)
|
||||
Reference in New Issue
Block a user