normalize initd state modeling and stabilize synthetic initd PID mapping
add IPC backpressure/drop telemetry and jittered swarm retry tiers harden socket bridge timeout/lifecycle handling and replace recv polling with readiness signaling improve shell background child isolation and worker offload fallback/output diagnostics add var-log fast append path to reduce read-concat-write amplification
This commit is contained in:
@@ -62,7 +62,9 @@ function readSwarmPolicyEnv(env) {
|
||||
* banUntilMs: number,
|
||||
* ewmaLatencyMs: number,
|
||||
* lastLatencyMs: number | null,
|
||||
* reconnectBudget: number
|
||||
* reconnectBudget: number,
|
||||
* earliestRetryAtMs: number,
|
||||
* retryTier: 'none' | 'short' | 'medium' | 'long' | 'xlong'
|
||||
* }} PeerState
|
||||
*/
|
||||
|
||||
@@ -99,13 +101,33 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
banUntilMs: 0,
|
||||
ewmaLatencyMs: 0,
|
||||
lastLatencyMs: null,
|
||||
reconnectBudget: 32
|
||||
reconnectBudget: 32,
|
||||
earliestRetryAtMs: 0,
|
||||
retryTier: 'none'
|
||||
}
|
||||
this._peers.set(k, st)
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
_retryDelayFor(st) {
|
||||
const n = Math.max(0, Number(st.consecutiveFail) || 0)
|
||||
const tier =
|
||||
n >= 9 ? 'xlong' : n >= 6 ? 'long' : n >= 4 ? 'medium' : n >= 2 ? 'short' : 'none'
|
||||
const base =
|
||||
tier === 'xlong'
|
||||
? 15000
|
||||
: tier === 'long'
|
||||
? 8000
|
||||
: tier === 'medium'
|
||||
? 3000
|
||||
: tier === 'short'
|
||||
? 800
|
||||
: 0
|
||||
const jitter = base > 0 ? Math.floor(base * 0.3 * Math.random()) : 0
|
||||
return { tier, delayMs: base + jitter }
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} peerKey
|
||||
* @param {boolean} ok
|
||||
@@ -119,6 +141,8 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
if (ok) {
|
||||
st.ok++
|
||||
st.consecutiveFail = 0
|
||||
st.retryTier = 'none'
|
||||
st.earliestRetryAtMs = 0
|
||||
const lat =
|
||||
typeof probeMeta.latencyMs === 'number' && Number.isFinite(probeMeta.latencyMs)
|
||||
? Math.max(0, probeMeta.latencyMs)
|
||||
@@ -137,6 +161,9 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
} else {
|
||||
st.fail++
|
||||
st.consecutiveFail++
|
||||
const retry = this._retryDelayFor(st)
|
||||
st.retryTier = retry.tier
|
||||
st.earliestRetryAtMs = now + retry.delayMs
|
||||
if (st.consecutiveFail >= this._cfg.failsBeforeBan) {
|
||||
st.banCount++
|
||||
const base = Math.min(
|
||||
@@ -146,6 +173,8 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
const jitter = Math.floor(base * 0.2 * Math.random())
|
||||
st.banUntilMs = now + base + jitter
|
||||
st.consecutiveFail = 0
|
||||
st.retryTier = 'xlong'
|
||||
st.earliestRetryAtMs = st.banUntilMs
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,6 +203,7 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
const now = Date.now()
|
||||
if (!st) return true
|
||||
if (st.banUntilMs > now) return false
|
||||
if (st.earliestRetryAtMs > now) return false
|
||||
if (st.reconnectBudget <= 0) return false
|
||||
return true
|
||||
}
|
||||
@@ -251,7 +281,9 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
id,
|
||||
...st,
|
||||
banned: st.banUntilMs > now,
|
||||
banRemainingMs: st.banUntilMs > now ? st.banUntilMs - now : 0
|
||||
banRemainingMs: st.banUntilMs > now ? st.banUntilMs - now : 0,
|
||||
retryWaitMs:
|
||||
st.earliestRetryAtMs > now ? st.earliestRetryAtMs - now : 0
|
||||
})),
|
||||
atMs: now
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user