> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wasabihosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Garry's Mod Server Optimization Guide

> How to optimize your Garry's Mod server for better performance

# Introduction to Garry's Mod Server Optimization

Optimizing your Garry's Mod server is essential for ensuring a smooth gaming experience for your players. This guide covers various techniques to improve your server's performance on Wasabi Hosting's Gamepanel platform.

## Hardware Allocation

Garry's Mod servers can be demanding, especially with multiple addons and players. Here are Wasabi Hosting's recommended resource allocations:

<Accordion title="Resource Recommendations">
  | Server Size | RAM   | CPU      | Recommended Player Count |
  | ----------- | ----- | -------- | ------------------------ |
  | Small       | 4GB   | 2 Cores  | Up to 16 players         |
  | Medium      | 8GB   | 4 Cores  | Up to 32 players         |
  | Large       | 16GB+ | 6+ Cores | 32+ players              |
</Accordion>

<Tip>
  With Garry's Mod, CPU performance is often more important than raw RAM. A server with fewer, faster cores may outperform one with more, slower cores. Wasabi Hosting's optimized plans are specifically designed with this in mind.
</Tip>

## Startup Parameters

Optimize your server's startup flags in the Wasabi Hosting Gamepanel for better performance:

```
./srcds_run -game garrysmod -console -tickrate 66 +map gm_construct +host_workshop_collection 123456789 +maxplayers 32 -authkey YOURAUTHKEY -disableluarefresh -softrestart
```

### Key Parameters Explained

| Parameter              | Description                      | Recommended Value                               |
| ---------------------- | -------------------------------- | ----------------------------------------------- |
| **-tickrate**          | Server tick rate                 | 66 (default) or 100 for better hit registration |
| **+maxplayers**        | Maximum player slots             | Based on your server capacity                   |
| **-authkey**           | Workshop authentication          | Required for workshop content                   |
| **-disableluarefresh** | Prevents constant Lua refreshing | Recommended for performance                     |
| **-softrestart**       | Allows cleaner restarts          | Recommended for stability                       |

<Warning>
  Setting tickrate too high (above 100) can cause performance issues on most hardware.
</Warning>

## Server Configuration Files

### server.cfg Optimization

Your `server.cfg` file contains important settings that affect server performance:

```cfg theme={null}
// Network Settings
sv_minrate 20000
sv_maxrate 100000
sv_maxupdaterate 66
sv_minupdaterate 33
sv_maxcmdrate 66
sv_mincmdrate 33
net_maxfilesize 64
decalfrequency 10

// Performance Settings
sv_parallel_packentities 1
sv_parallel_sendsnapshot 1
sv_lan 0
sv_region 0
sv_loadingurl "https://yourloadingurl.com"
sv_downloadurl "https://yourfastdownloadurl.com"

// Entity Settings
gmod_physiterations 4
sv_turbophysics 1
sv_defaultdeployspeed 1.5
sv_client_predict 1
sv_client_min_interp_ratio -1
sv_client_max_interp_ratio 2
sv_stats 0
sv_allowcslua 0
sv_cheats 0
sv_hibernate_think 1

// Gameplay Settings
sbox_godmode 0
sbox_plpldamage 1
sbox_playergod 0
sbox_noclip 1
```

<Info>
  The `sv_parallel_packentities` and `sv_parallel_sendsnapshot` settings utilize multi-threading capabilities in the Source engine, which can significantly improve performance on multi-core systems.
</Info>

## Addon Management

Addons are the primary cause of lag on Garry's Mod servers. Here are some tips for managing them:

### Identifying Resource-Heavy Addons

Use these tools to identify problematic addons:

* **gm\_debug** - Shows Lua memory usage
* **ULX Lag Checker** - Tracks hook call times
* **FProfiler** - Detailed profiling of Lua functions

### Optimizing Addons

1. **Limit total addons** - Only use what's necessary for your server
2. **Use collection IDs** - Faster and more reliable than individual workshop IDs
3. **Avoid redundant addons** - Many addons have overlapping functionality
4. **Update regularly** - Outdated addons may have unpatched performance issues
5. **Check compatibility** - Ensure addons work together without conflicts

<Warning>
  Some popular addons like Wiremod, ACF, and certain RP systems can be extremely resource-intensive. Consider lighter alternatives if performance is a priority.
</Warning>

## FastDL Setup

Setting up FastDL (Fast Download) significantly reduces loading times for players:

1. **Create a web server** for hosting content files
2. Configure these settings in your server.cfg:
   ```cfg theme={null}
   sv_downloadurl "http://your-fastdl-url.com"
   sv_allowdownload 0
   sv_allowupload 0
   ```
3. **Compress content files** using bzip2
4. **Organize files** in the proper directory structure (/maps, /materials, etc.)

## Database Optimization

If your server uses MySQL (common for DarkRP and similar gamemodes):

1. **Use connection pooling** to reduce database overhead
2. **Index frequently queried fields** for faster lookups
3. **Regular database maintenance** to prevent bloat
4. **Consider SSD storage** for database files

## Console Settings for Optimization

Run these commands in your server console for immediate optimization:

```
sv_hibernate_when_empty 1
r_3dsky 0  
host_sleep 0
fps_max 600
```

## Gamemode-Specific Optimizations

### DarkRP Optimization

For DarkRP servers, add these settings to `darkrp_config/settings.lua`:

```lua theme={null}
GM.Config.minCopsToRaid = 2                        -- Prevents constant raiding
GM.Config.minCopsToVendorCrack = 2                 -- Reduces unnecessary theft events
GM.Config.pricecheckerHideNonBuyable = true        -- Reduces UI overhead
GM.Config.restrictallteams = true                  -- Better job management
GM.Config.playerFrozeNotification = false          -- Reduces notification spam
GM.Config.disableNoclip = false                    -- Allow admin noclip
```

### Sandbox Optimization

For Sandbox servers:

```lua theme={null}
-- Add to server.cfg
sbox_maxprops 100                                  -- Limit props per player
sbox_maxragdolls 5                                 -- Limit ragdolls
sbox_maxvehicles 6                                 -- Limit vehicles
sbox_maxballoons 10                                -- Limit balloons
sbox_maxeffects 10                                 -- Limit effects
sbox_maxdynamite 10                                -- Limit dynamite
sbox_maxlamps 5                                    -- Limit lamps
sbox_maxthrusters 20                               -- Limit thrusters
sbox_maxwheels 20                                  -- Limit wheels
sbox_maxemitters 5                                 -- Limit emitters
sbox_maxspawners 3                                 -- Limit spawners
sbox_maxturrets 2                                  -- Limit turrets
```

## Routine Maintenance

Implement these maintenance routines on your Wasabi Hosting server:

1. **Regular map changes** every 6-12 hours
2. **Scheduled restarts** to clear memory leaks
3. **Prop cleanup** every 30-60 minutes:
   ```
   lua_run for k, v in pairs(ents.FindByClass("prop_physics")) do v:Remove() end
   ```
4. **Player data cleanup** - Purge inactive player data monthly

By implementing these optimization techniques, you should see a significant improvement in your Garry's Mod server's performance on Wasabi Hosting. If you continue to experience issues, contact our support team for assistance.

## Network Optimization

1. **DDoS protection** - Use our built-in firewall or a service like Cloudflare
2. **Connection throttling** - Prevent excessive reconnects:
   ```
   sv_connectthrottle 60
   ```
3. **Packet rate configuration** - Balanced settings for various connections:
   ```
   sv_minrate 20000
   sv_maxrate 100000
   ```

## Advanced Lua Optimizations

For server developers:

1. **Use timer.Simple** instead of timer.Create for one-time events
2. **Avoid table.concat** in frequent operations
3. **Cache results** of expensive calculations
4. **Use ENT:NextThink** to reduce entity think frequency
5. **Implement think spreading** to distribute processing across frames

```lua theme={null}
-- Example of think spreading
local thinkOffset = 0
local entitiesToThink = 5 -- Process 5 entities per frame

hook.Add("Think", "ThinkSpreading", function()
    local entities = ents.GetAll()
    local count = #entities
    
    for i=1, entitiesToThink do
        local index = (thinkOffset + i) % count
        if index > 0 then
            local ent = entities[index]
            if IsValid(ent) and ent.CustomThink then
                ent:CustomThink()
            end
        end
    end
    
    thinkOffset = (thinkOffset + entitiesToThink) % count
end)
```

## Common Performance Issues

### Prop Spam

Control prop limits with these plugins:

* **ULX Prop Protection**
* **FPP (Falco's Prop Protection)**
* **SPP (Simple Prop Protection)**

### Lua Errors

1. Install **ulib\_errors** or similar to log errors
2. Check logs regularly for recurring errors
3. Fix or remove problematic addons

### Memory Leaks

1. Monitor RAM usage trends
2. Restart server when memory usage becomes excessive
3. Check for addons that gradually consume more memory
