A well-optimized Lavalink server delivers smooth audio with minimal resource usage. This guide covers proven optimization techniques to get the best performance from your Lavalink setup.
Configure heap size based on your usage:
# For 50-100 players
java -Xms256M -Xmx512M -jar Lavalink.jar
# For 100-300 players
java -Xms512M -Xmx1G -jar Lavalink.jar
# For 300+ players
java -Xms1G -Xmx2G -jar Lavalink.jar
Key settings:
-Xms - Initial heap (set to 50% of max)-Xmx - Maximum heap (based on available RAM)Use G1GC for balanced performance:
java -XX:+UseG1GC \
-XX:G1HeapRegionSize=4M \
-XX:+ParallelRefProcEnabled \
-XX:+AlwaysPreTouch \
-jar Lavalink.jar
For low-latency requirements:
java -XX:+UseZGC \
-XX:+ZGenerational \
-jar Lavalink.jar
java -Xms512M -Xmx1G \
-XX:+UseG1GC \
-XX:G1HeapRegionSize=4M \
-XX:+ParallelRefProcEnabled \
-XX:+AlwaysPreTouch \
-XX:MaxGCPauseMillis=50 \
-XX:+DisableExplicitGC \
-Djava.net.preferIPv4Stack=true \
-jar Lavalink.jar
lavalink:
server:
password: "your_secure_password"
sources:
youtube: true
soundcloud: true
bandcamp: true
twitch: true
http: true
local: false
bufferDurationMs: 400
frameBufferDurationMs: 5000
youtubePlaylistLoadLimit: 6
playerUpdateInterval: 5
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
gc-warnings: true
server:
port: 2333
address: 0.0.0.0
bufferDurationMs - Audio buffer before playback starts
frameBufferDurationMs - Frame buffer size
Controls how often player state updates are sent:
playerUpdateInterval: 5 # seconds
Lower values = more accurate progress but more network traffic.
Choose a server location close to:
Discord Voice Server Regions:
Use fast DNS resolvers:
# In /etc/resolv.conf
nameserver 1.1.1.1
nameserver 8.8.8.8
Increase system limits for many connections:
# In /etc/sysctl.conf
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.core.netdev_max_backlog = 65535
YouTube is the most common source. Optimize with:
lavalink:
server:
youtubePlaylistLoadLimit: 6 # Limit playlist loading
youtubeSearchEnabled: true
Consider using youtube-source plugin for better reliability:
plugins:
- dependency: "dev.lavalink.youtube:youtube-plugin:1.0.0"
repository: "https://maven.lavalink.dev/releases"
Spotify requires a plugin since it does not provide direct audio:
plugins:
- dependency: "com.github.topi314.lavasrc:lavasrc-plugin:4.0.0"
repository: "https://maven.topi.wtf/releases"
lavasrc:
spotify:
clientId: "your_client_id"
clientSecret: "your_client_secret"
metrics:
prometheus:
enabled: true
endpoint: /metrics
Reduce log verbosity in production:
logging:
level:
root: INFO
lavalink: INFO
request:
enabled: false
includeClientInfo: false
includeHeaders: false
includeQueryString: false
includePayload: false
Implement automatic cleanup for inactive players:
// In your bot code
setInterval(() => {
for (const player of manager.players.values()) {
if (!player.playing && !player.paused) {
player.destroy();
}
}
}, 300000); // Every 5 minutes
Prevent memory issues from large queues:
const MAX_QUEUE_SIZE = 500;
if (player.queue.length >= MAX_QUEUE_SIZE) {
return message.reply('Queue is full!');
}
FROM eclipse-temurin:21-jre-alpine
ENV JAVA_OPTS="-Xms512M -Xmx1G -XX:+UseG1GC"
WORKDIR /app
COPY Lavalink.jar .
COPY application.yml .
EXPOSE 2333
CMD java \$JAVA_OPTS -jar Lavalink.jar
version: '3.8'
services:
lavalink:
build: .
ports:
- "2333:2333"
environment:
- JAVA_OPTS=-Xms512M -Xmx1G -XX:+UseG1GC
deploy:
resources:
limits:
memory: 1.5G
reservations:
memory: 512M
restart: unless-stopped
Causes:
Solutions:
Causes:
Solutions:
Causes:
Solutions:
# Check response time
curl -w "%{time_total}\n" -o /dev/null -s http://localhost:2333/version
# Monitor during load
watch -n 1 'curl -s http://localhost:2333/metrics | grep players'
| Players | RAM Usage | CPU Usage |
|---|---|---|
| 10 | ~200MB | 5-10% |
| 50 | ~400MB | 15-25% |
| 100 | ~600MB | 25-40% |
| 250 | ~1GB | 40-60% |
Lavalink optimization involves JVM tuning, configuration adjustments, and proper resource management. Start with the recommended settings and adjust based on your monitoring data.
VexaNode provides pre-optimized Lavalink hosting with all these optimizations applied, so you can focus on building your music bot instead of server tuning.
Join thousands of satisfied users and experience the VexaNode difference today.
View Plans