This document outlines all assumptions and implementation details for the microCloud simulation, particularly regarding latency, bandwidth, and device heterogeneity.
- Implementation: Bandwidth is randomly generated for each peer using a uniform distribution within the configured min/max range
- Formula:
bandwidth = bandwidthMin + Math.random() * (bandwidthMax - bandwidthMin) - Default Range: 10-100 Mbps (configurable via
deviceHeterogeneity.bandwidthMinanddeviceHeterogeneity.bandwidthMax) - Location:
server/simulation.ts:223increatePeer()function - Verification: The implementation correctly uses the configured min/max values from
config.deviceHeterogeneity, falling back to defaults (10-100 Mbps) if not specified
- Implementation: Latency varies based on peer position (index) with added randomness
- Formula:
- Base latency:
latencyMin + (index / totalPeers) * (latencyMax - latencyMin) - With randomness:
baseLatency + (Math.random() - 0.5) * ((latencyMax - latencyMin) * 0.1)
- Base latency:
- Default Range: 10-250 ms (configurable via
deviceHeterogeneity.latencyMinanddeviceHeterogeneity.latencyMax) - Location:
server/simulation.ts:218-219increatePeer()function - Note: Early peers (low index) tend to have lower latency, simulating better network conditions
- Location:
server/simulation.ts:540-576insimulatePeerJoin()function - Base Delay: Uses
config.anchorSignalingLatency(default: 100ms) oranchorSignalingLatency * 2for direct joins - Bandwidth Factor:
- Formula:
joinLatency = baseJoinLatency * (maxBandwidth / peerBandwidth) - Lower bandwidth peers experience proportionally longer join delays
- Reference bandwidth:
config.deviceHeterogeneity.bandwidthMax ?? 100Mbps
- Formula:
- Assumption: Lower bandwidth connections take longer to establish signaling connections
- Example:
- Peer with 10 Mbps:
100ms * (100/10) = 1000msjoin delay - Peer with 100 Mbps:
100ms * (100/100) = 100msjoin delay
- Peer with 10 Mbps:
- Location:
server/simulation.ts:741-746beforepeerBrowser.requestResource()call - Base Delay: 10ms base delay
- Bandwidth Factor:
- Formula:
requestDelay = baseRequestDelay * (maxBandwidth / peerBandwidth) - Lower bandwidth peers take longer to initiate requests
- Reference bandwidth:
config.deviceHeterogeneity.bandwidthMax ?? 100Mbps
- Formula:
- Assumption: Lower bandwidth peers have slower request processing/initiation
- Example:
- Peer with 10 Mbps:
10ms * (100/10) = 100msrequest delay - Peer with 100 Mbps:
10ms * (100/100) = 10msrequest delay
- Peer with 10 Mbps:
- Location:
server/mock-webrtc-client.ts:215-224insendFile()method - Transfer Time Calculation:
- Formula:
transferTimeMs = ((bytes.length * 8) / (bandwidth * 1000000)) * 1000 - Accounts for actual data transfer time based on bandwidth
- Formula:
- Chunk Delay:
chunkDelay = Math.max(1, transferTimeMs / totalChunks) - Total Delay per Chunk:
chunkDelay + latency - Assumption: Transfer time is directly proportional to file size and inversely proportional to bandwidth
- Note: This is the sender's bandwidth affecting how fast chunks can be sent
- Location:
server/mock-webrtc-client.ts:332-352inreceiveMessage()forfile-chunkcase - Base Delay: 2ms base processing delay
- Bandwidth Factor:
- Formula:
receiveDelay = baseReceiveDelay * (referenceBandwidth / peerBandwidth) - Lower bandwidth peers take longer to process received chunks
- Reference bandwidth: 100 Mbps (fixed)
- Formula:
- Assumption: Lower bandwidth peers have slower processing/decoding of received chunks
- Implementation: Uses
setTimeout()to simulate async processing delay - Example:
- Peer with 10 Mbps:
2ms * (100/10) = 20msreceive delay per chunk - Peer with 100 Mbps:
2ms * (100/100) = 2msreceive delay per chunk
- Peer with 10 Mbps:
All latency components use a linear inverse relationship with bandwidth:
- Formula Pattern:
delay = baseDelay * (maxBandwidth / peerBandwidth) - Rationale: Lower bandwidth = higher delay (inverse relationship)
- Linearity: The relationship is linear, not exponential, for simplicity and predictability
- Join Latency: Bandwidth-dependent delay when peer joins network
- Request Latency: Bandwidth-dependent delay before making resource request
- Transfer Latency: Bandwidth-dependent time to send chunks (sender's bandwidth)
- Receive Latency: Bandwidth-dependent time to process received chunks (receiver's bandwidth)
-
Network Latency (
peer.latency): Represents round-trip time (RTT) in milliseconds- Used for: Network propagation delays, message delivery delays
- Location: Set in
createPeer()based on device heterogeneity config - Range: 10-250ms (default, configurable)
-
Bandwidth (
peer.bandwidth): Represents data transfer capacity in Mbps- Used for: Transfer time calculations, processing delays
- Location: Set in
createPeer()based on device heterogeneity config - Range: 10-100 Mbps (default, configurable)
- All bandwidth values are in Mbps (Megabits per second)
- All bandwidth-based delays use linear scaling
- Rationale: Simple, predictable, and computationally efficient
- Alternative Considered: Exponential scaling was considered but rejected for simplicity
- Future Enhancement: Could be made configurable (linear vs exponential)
The baseline experiment simulates a traditional origin-server-only architecture where all requests go directly to the origin server with no peer-to-peer caching. This is used for comparison with the P2P approach.
Location: server/simulation.ts:906-1022 in requestFromOrigin() function when config.baselineMode === true
The baseline uses a realistic server model with proper FIFO queuing, timeout handling, and load-based performance degradation.
Hardcoded Constants:
SERVER_BASE_LATENCY = 20- Base server processing latency (ms) - realistic for a good serverMAX_QUEUE_SIZE = 100- Maximum requests that can wait in queueREQUEST_TIMEOUT = 30000- 30 second timeout for requestsmaxConcurrentRequests = 20(flash crowd) or40(normal) - Server capacity (configurable based on flash crowd mode)
Server Model: Realistic server behavior with proper queuing:
- FIFO Queue: Requests wait in first-in-first-out order when server is at capacity
- Queue Size Limit: Maximum 100 requests can wait in queue
- Timeout Handling: Requests timeout after 30 seconds if still waiting
- Immediate Rejection: If queue is full, requests are immediately rejected (simulates "503 Service Unavailable")
Load-Based Processing Latency:
-
Normal Load (
loadRatio ≤ 0.8):processingLatency = SERVER_BASE_LATENCY(20ms)- No degradation, normal server performance
-
High Load (
loadRatio > 0.8):processingLatency = SERVER_BASE_LATENCY * (1 + (loadRatio - 0.8) * 5)- Linear degradation due to resource contention (CPU, memory, I/O):
- At 80% capacity:
20 * (1 + (0.8 - 0.8) * 5) = 20ms(1.0x) - At 90% capacity:
20 * (1 + (0.9 - 0.8) * 5) = 30ms(1.5x) - At 100% capacity:
20 * (1 + (1.0 - 0.8) * 5) = 40ms(2.0x)
- At 80% capacity:
Queue Behavior:
- Server Available: If
activeRequests < maxConcurrentRequests, request is processed immediately - Server at Capacity: If server is full but queue has space, request waits in FIFO queue
- Queue Full: If queue is full (100 requests), request is immediately rejected with 10ms latency
- Timeout: If request waits in queue longer than 30 seconds, it times out and fails
- FIFO Processing: When a server slot becomes available, the next request in queue is processed
Total Latency:
totalLatency = peer.latency + serverLatency- Server latency includes: queue wait time + processing time
- Measured from request arrival to completion
- Network latency (
peer.latency) represents RTT to server
Assumptions:
- Server has limited concurrent request capacity (20-40 requests depending on flash crowd mode)
- Requests beyond capacity wait in FIFO queue (up to 100 requests)
- Server performance degrades under load (linear degradation starting at 80% capacity)
- Queue full or timeout results in request failure
- No bandwidth-based delays for baseline requests (only network latency + server processing)
Hardcoded Values Summary:
| Constant | Value | Description |
|---|---|---|
SERVER_BASE_LATENCY |
20ms | Base server processing latency |
maxConcurrentRequests (normal) |
40 | Max concurrent requests (normal mode) |
maxConcurrentRequests (flash crowd) |
20 | Max concurrent requests (flash crowd mode) |
MAX_QUEUE_SIZE |
100 | Maximum requests in queue |
REQUEST_TIMEOUT |
30000ms | Request timeout (30 seconds) |
| Queue rejection latency | 10ms | Latency for rejected requests (queue full) |
| Load degradation threshold | 0.8 (80%) | Load ratio where degradation starts |
| Load degradation multiplier | 5x | Multiplier for load-based degradation |
- Request Initiation: Peer makes request to origin server
- Network Latency:
peer.latency(RTT to server) - Server Queuing: If server at capacity, request waits in queue
- Server Processing: Server processes request (latency depends on load)
- Response: Response sent back (network latency already included in
peer.latency)
Server Capacity:
- Limited concurrent request handling (20-40 requests depending on flash crowd mode)
- Queue size limits (100 requests max)
- Capacity does not scale with number of peers
Server Performance:
- Base processing latency: 20ms (assumes well-optimized server)
- Performance degrades under load (linear degradation starting at 80% capacity)
- Requests fail when queue is full or timeout occurs (30 second timeout)
No Bandwidth Delays:
- Important: Baseline requests do NOT include bandwidth-based delays
- Only network latency (
peer.latency) and server processing delays - This makes baseline faster than P2P for high-bandwidth scenarios, but slower when server is overloaded
Flash Crowd Behavior:
- Lower server capacity during flash crowds (20 vs 40 concurrent requests)
- Simulates server being overwhelmed by sudden traffic spike
- Higher queuing delays and failure rates
Failure Handling:
- Failed requests counted as cache misses
- Failure scenarios:
- Queue full: Immediate rejection with 10ms latency
- Timeout: Request times out after 30 seconds
- No retry logic (request fails immediately)
Baseline Advantages:
- No bandwidth-based delays for requests
- Direct server access (no peer discovery overhead)
Baseline Disadvantages:
- Server becomes bottleneck (limited capacity)
- All requests hit origin (no caching)
- Server overload causes high latency and failures
- No load distribution (all load on single server)
P2P Advantages:
- Load distributed across peers
- Caching reduces origin requests
- No single bottleneck
P2P Disadvantages:
- Bandwidth-based delays for all operations
- Peer discovery overhead
- Potential for peer failures
When testing latency behavior:
- Low Bandwidth Peers: Should experience significantly longer delays across all operations
- High Bandwidth Peers: Should experience minimal delays
- Bandwidth Range: Test with different min/max ranges to verify scaling
- Edge Cases: Test with very low bandwidth (e.g., 1 Mbps) to ensure no division by zero errors
- Baseline Overload: Test with many peers to observe server overload behavior
- Flash Crowds: Compare baseline vs P2P during flash crowd scenarios