Update connection limits at runtime without server restart
ShibuDB supports dynamic connection limiting that allows you to update connection limits at runtime without restarting the server. This feature provides multiple ways to manage connection limits based on your operational needs.
ShibuDB provides three different ways to manage connection limits dynamically.
The server automatically starts a management HTTP server on port <main_port> + 1000
.
GET http://localhost:10090/health
Response:
{
"status": "healthy",
"service": "shibudb"
}
GET http://localhost:10090/stats
Response:
{
"active_connections": 45,
"max_connections": 1000,
"usage_percentage": 4.5,
"available_slots": 955
}
GET http://localhost:10090/limit
Response:
{
"current_limit": 1000,
"active_connections": 45
}
PUT http://localhost:10090/limit
Content-Type: application/json
{
"limit": 2000
}
Response:
{
"status": "success",
"new_limit": 2000,
"message": "Connection limit updated to 2000"
}
POST http://localhost:10090/limit/increase
Content-Type: application/json
{
"amount": 500
}
Response:
{
"status": "success",
"old_limit": 1000,
"new_limit": 1500,
"increase_amount": 500,
"message": "Connection limit increased from 1000 to 1500"
}
POST http://localhost:10090/limit/decrease
Content-Type: application/json
{
"amount": 200
}
Response:
{
"status": "success",
"old_limit": 1500,
"new_limit": 1300,
"decrease_amount": 200,
"message": "Connection limit decreased from 1500 to 1300"
}
Use the built-in CLI tool for easy management:
# Check current status
shibudb manager 9090 status
# View detailed statistics
shibudb manager 9090 stats
# Set specific limit
shibudb manager 9090 limit 2000
# Increase limit by 500
shibudb manager 9090 increase 500
# Decrease limit by 200
shibudb manager 9090 decrease 200
# Check server health
shibudb manager 9090 health
Send signals to the server process for quick adjustments:
# Increase limit by 100
kill -USR1 <server_pid>
# Decrease limit by 100
kill -USR2 <server_pid>
Understanding how dynamic connection limiting works internally.
type ConnectionManager struct {
maxConnections int32
activeConnections int32
semaphore chan struct{}
connections sync.Map
mu sync.RWMutex
limitUpdateChan chan int32
shutdownChan chan struct{}
}
Common scenarios and practical examples for different environments.
# Start server with conservative limit
sudo shibudb start 9090 1000
# Monitor usage
shibudb manager 9090 stats
# Scale up during peak hours
shibudb manager 9090 increase 500
# Scale down during off-peak
shibudb manager 9090 decrease 300
# Start with low limit for testing
sudo shibudb start 9090 100
# Increase for load testing
shibudb manager 9090 limit 1000
# Reset to original limit
shibudb manager 9090 limit 100
#!/bin/bash
# Auto-scale based on usage
while true; do
# Get current usage
usage=$(curl -s http://localhost:10090/stats | jq -r '.usage_percentage')
if (( $(echo "$usage > 80" | bc -l) )); then
echo "High usage detected: ${usage}%"
curl -X POST http://localhost:10090/limit/increase \
-H "Content-Type: application/json" \
-d '{"amount": 200}'
elif (( $(echo "$usage < 30" | bc -l) )); then
echo "Low usage detected: ${usage}%"
curl -X POST http://localhost:10090/limit/decrease \
-H "Content-Type: application/json" \
-d '{"amount": 100}'
fi
sleep 60
done
Common error scenarios and troubleshooting steps.
{
"error": "cannot set limit to 500 when 750 connections are active",
"status": "failed"
}
{
"error": "connection limit must be positive",
"status": "failed"
}
Error: Failed to connect to management server: connection refused
shibudb manager 9090 health
<main_port> + 1000
Key metrics and alerting strategies for connection management.
# Alert when usage exceeds 80%
usage=$(shibudb manager 9090 stats | grep "Usage Percentage" | awk '{print $3}' | sed 's/%//')
if (( $(echo "$usage > 80" | bc -l) )); then
echo "WARNING: High connection usage: ${usage}%"
# Send alert via email, Slack, etc.
fi
# Alert when limit changes
old_limit=$(shibudb manager 9090 status | grep "Current Limit" | awk '{print $3}')
sleep 60
new_limit=$(shibudb manager 9090 status | grep "Current Limit" | awk '{print $3}')
if [ "$old_limit" != "$new_limit" ]; then
echo "INFO: Connection limit changed from $old_limit to $new_limit"
fi
Recommended practices for effective connection management.
# Start with lower limits and scale up
sudo shibudb start 9090 500
# Set up monitoring
watch -n 30 'shibudb manager 9090 stats'
# Pre-configure scaling scripts
cat > scale_up.sh << 'EOF'
#!/bin/bash
shibudb manager 9090 increase 200
echo "$(date): Increased connection limit"
EOF
cat > scale_down.sh << 'EOF'
#!/bin/bash
shibudb manager 9090 decrease 100
echo "$(date): Decreased connection limit"
EOF
Security measures for the management API and connection limiting.
# Restrict management API access
iptables -A INPUT -p tcp --dport 10090 -s 127.0.0.1 -j ACCEPT
iptables -A INPUT -p tcp --dport 10090 -j DROP
# Use SSH tunnel for remote management
ssh -L 10090:localhost:10090 user@server
Understanding the performance characteristics of dynamic connection limiting.
# Test connection acquisition performance
time for i in {1..1000}; do
shibudb manager 9090 status > /dev/null
done
# Test limit update performance
time shibudb manager 9090 increase 100