Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

checkpoint: File edit:

rUv6d521db8bb3a
diff --git a/v3/@claude-flow/swarm/src/message-bus.ts b/v3/@claude-flow/swarm/src/message-bus.ts
index e5b26e5c8b..53c9da2adc 100644
--- a/v3/@claude-flow/swarm/src/message-bus.ts
+++ b/v3/@claude-flow/swarm/src/message-bus.ts
@@ -339,30 +339,34 @@ export class MessageBus extends EventEmitter implements IMessageBus {
}
private startStatsCollection(): void {
- setInterval(() => {
+ this.statsInterval = setInterval(() => {
this.calculateMessagesPerSecond();
}, 1000);
}
private calculateMessagesPerSecond(): void {
const now = Date.now();
+ const entry = { timestamp: now, count: this.stats.totalMessages };
- // Track message count per second
- this.messageHistory.push({
- timestamp: now,
- count: this.stats.totalMessages,
- });
-
- // Keep only last 60 seconds
- this.messageHistory = this.messageHistory.filter(
- h => now - h.timestamp < 60000
- );
+ // Use circular buffer pattern - O(1) instead of O(n) filter
+ if (this.messageHistory.length < MessageBus.MAX_HISTORY_SIZE) {
+ this.messageHistory.push(entry);
+ } else {
+ this.messageHistory[this.messageHistoryIndex] = entry;
+ this.messageHistoryIndex = (this.messageHistoryIndex + 1) % MessageBus.MAX_HISTORY_SIZE;
+ }
+ // Calculate messages per second from history
if (this.messageHistory.length >= 2) {
- const oldest = this.messageHistory[0];
- const newest = this.messageHistory[this.messageHistory.length - 1];
- const seconds = (newest.timestamp - oldest.timestamp) / 1000;
- const messages = newest.count - oldest.count;
+ // Find oldest valid entry (within last 60 seconds)
+ let oldest = entry;
+ for (const h of this.messageHistory) {
+ if (h.timestamp < oldest.timestamp && now - h.timestamp < 60000) {
+ oldest = h;
+ }
+ }
+ const seconds = (now - oldest.timestamp) / 1000;
+ const messages = entry.count - oldest.count;
this.stats.messagesPerSecond = seconds > 0 ? messages / seconds : 0;
}