Memory Management
PocketMine-MP includes sophisticated memory management to prevent crashes and maintain performance.Memory Limits
Configure memory limits inpocketmine.yml:
pocketmine.yml
The memory manager checks usage every
check-rate ticks and triggers garbage collection when soft limits are exceeded.Understanding Memory Limits
global-limit vs main-limit
global-limit vs main-limit
- global-limit: Total memory used by all threads (main + workers)
- main-limit: Memory used only by the main server thread
- Set to
0to disable soft limiting
Soft limit vs hard limit
Soft limit vs hard limit
- Soft limits (global-limit, main-limit): Trigger memory cleanup when exceeded
- Hard limits (main-hard-limit): Stop the server/worker when exceeded
- Hard limits prevent PHP fatal errors and crashes
Low memory behavior
Low memory behavior
When soft limits are exceeded, PocketMine-MP automatically:
- Clears chunk caches
- Runs garbage collection
- Reduces view distance to
max-chunks.chunk-radius - Fires
LowMemoryEventfor plugins to free resources
Memory Recommendations
Small Server
1-20 players
- main-hard-limit:
1024MB - 2-4 GB total RAM
- view-distance:
8
Medium Server
20-50 players
- main-hard-limit:
2048MB - 4-8 GB total RAM
- view-distance:
8-10
Large Server
50-100 players
- main-hard-limit:
4096MB - 8-16 GB total RAM
- view-distance:
10-12
Mega Server
100+ players
- main-hard-limit:
8192+MB - 16+ GB total RAM
- view-distance:
12+ - Multiple worlds/instances
Garbage Collection
- Periodically based on
period - During low memory conditions
- When memory dumps are created
Decreasing the GC period increases CPU usage but may prevent memory buildup. Only change if experiencing memory issues.
Memory Dumps
Create memory dumps for debugging memory leaks:CPU Optimization
Async Workers
Async workers handle background tasks without blocking the main thread:- World generation
- Chunk compression
- Plugin async tasks
- Web requests
Chunk Management
Chunk Sending
Increasing
per-tick speeds up world loading but increases network and CPU usage. Decrease if experiencing lag during player joins.Chunk Ticking
- Lower
tick-radius: Better performance, slower crop growth - Lower
blocks-per-subchunk-per-tick: Better performance, slower events
Chunk Generation
View Distance
Inserver.properties:
- ~60-100 KB RAM per chunk (loaded)
- Increased CPU for chunk ticking
- Higher network bandwidth
View distance calculation
View distance calculation
Total chunks loaded per player =
(view-distance * 2 + 1)²- view-distance 4: 81 chunks
- view-distance 8: 289 chunks
- view-distance 12: 625 chunks
Recommended values
Recommended values
- 4-6: Budget hosting, many plugins
- 8-10: Standard servers (recommended)
- 12-16: High-performance servers
- 16+: Dedicated hardware only
Network Optimization
Compression
MTU Size
Query Configuration
Inserver.properties:
Storage Optimization
World Format
Auto-save Interval
Inpocketmine.yml:
server.properties:
Monitoring Performance
Timings
Generate detailed performance reports:Status Command
- Current TPS (ticks per second)
- Memory usage
- Player count
- Uptime
Target TPS is 20. Values consistently below 19 indicate performance issues.
Garbage Collection Stats
Performance Checklist
Set appropriate memory limits
Configure
main-hard-limit based on available RAM (see recommendations above)Troubleshooting Performance Issues
Low TPS (< 19)
Low TPS (< 19)
Causes:
- Too many entities/mobs
- Heavy plugins
- Large redstone contraptions
- Excessive chunk ticking
- Reduce
tick-radius - Disable expensive block ticking
- Remove or optimize heavy plugins
- Use timings to identify specific lag sources
High memory usage
High memory usage
Causes:
- Too many loaded chunks
- Memory leaks in plugins
- High player count
- Large view distance
- Reduce
view-distance - Enable soft memory limits
- Unload unused worlds
- Check plugins for memory leaks with memory dumps
High CPU usage
High CPU usage
Causes:
- High compression level
- Too many async workers
- Intensive world generation
- Heavy entity processing
- Lower
compression-level - Reduce
async-workers - Pre-generate worlds
- Limit entity spawning
Next Steps
Configuration
Review all configuration options
Troubleshooting
Resolve common issues