I mean, just look at me. I’m covered in them! So when Brent wanted to randomly make his server act crappy, I wrote a script for it.
Usual caveats here. Don’t run this in production. I’m not responsible for anything you do after you hit copy and paste. In fact, I’m not responsible for anything before or in between, either.
You are your own fault.
What does this thing do?It randomly generates values and changes some important configuration settings.
Max Degree of Parallelism Cost Threshold Max Memory Database compatibility levelThis was written for SQL Server 2016, on a box that had 384 GB of RAM. If your specs don’t line up, you may have to change the seed values here. I’m not putting any more development into this thing to automatically detect SQL version or memory in the server, because this was a one-off joke script to see how bad things could get.
How bad did they get? The server crashed multiple times.
Umpire sitsHere’s the script. I highly don’t recommend setting it up as an agent job that runs every 10 minutes.
Thanks for reading!
USE master;GO
ALTER PROCEDURE dbo.sp_ChaosSloth
AS
BEGIN
SET NOCOUNT ON
--Declare stuff
DECLARE @SQL NVARCHAR(MAX) = N''
DECLARE @MAXDOP INT = 0
DECLARE @MAXMEM INT = 0
DECLARE @CTP INT = 0
DECLARE @COMPAT INT = 0
DECLARE @isDoubleDown BIT = 0
DECLARE @nl NVARCHAR(10) = CHAR(10) + CHAR(13)
DECLARE @COMPAT_LEVELS TABLE (LVL INT)
--Valid compat levels
INSERT @COMPAT_LEVELS SELECT 100
INSERT @COMPAT_LEVELS SELECT 110
INSERT @COMPAT_LEVELS SELECT 120
INSERT @COMPAT_LEVELS SELECT 130
--Set up logging table
IF OBJECT_ID('DBAMetrics.dbo.ChaosSloth') IS NULL
CREATE TABLE DBAMetrics.dbo.ChaosSloth
(
RunID BIGINT IDENTITY(1,1),
RunTime DATETIME2(7) DEFAULT SYSUTCDATETIME(),
MaxDopSet INT,
CostThresholdSet INT,
MaxMemorySet INT,
CompatLevelSet INT,
isDoubleDownSet BIT
)
--Set random values
SELECT @MAXDOP = ABS(CHECKSUM(NEWID()) % 18),
@CTP = ABS(CHECKSUM(NEWID()) % 200),
@MAXMEM = ABS(CHECKSUM(NEWID()) % 358400) + 16384,
@COMPAT = LVL FROM @COMPAT_LEVELS ORDER BY NEWID()
--Always double down on 11
SELECT
@MAXDOP = CASE WHEN @CTP % 11 = 0 THEN 0 ELSE @MAXDOP END,
@CTP = CASE WHEN @CTP % 11 = 0 THEN 0 ELSE @CTP END,
@MAXMEM = CASE WHEN @CTP % 11 = 0 THEN 16384 ELSE @MAXMEM END,
@COMPAT = CASE WHEN @CTP % 11 = 0 THEN 100 ELSE @COMPAT END,
@isDoubleDown = CASE WHEN @CTP % 11 = 0 THEN 1 ELSE @isDoubleDown END
--Break stuff
INSERT DBAMetrics.dbo.ChaosSloth
(MaxDopSet, CostThresholdSet, MaxMemorySet, CompatLevelSet, isDoubleDownSet)
SELECT @MAXDOP, @CTP, @MAXMEM, @COMPAT, @isDoubleDown
--MAXDOP
SET @SQL = N'EXEC sys.sp_configure @configname = ''max degree of parallelism'', @configvalue = ' + CONVERT(NVARCHAR(100), @MAXDOP)
SET @SQL += @nl + N'RECONFIGURE WITH OVERRIDE'
PRINT @SQL
EXEC(@SQL)
--CTP
SET @SQL = N'EXEC sys.sp_configure @configname = ''cost threshold for parallelism'', @configvalue = ' + CONVERT(NVARCHAR(100), @CTP)
SET @SQL += @nl + N'RECONFIGURE WITH OVERRIDE'
PRINT @SQL
EXEC(@SQL)
--Max Memory
SET @SQL = N'EXEC sys.sp_configure @configname = ''max server memory (MB)'', @configvalue = ' + CONVERT(NVARCHAR(100), @MAXMEM)
SET @SQL += @nl + N'RECONFIGURE WITH OVERRIDE'
PRINT @SQL
EXEC(@SQL)
--Compat level
SET @SQL = N'ALTER DATABASE StackOverflow SET COMPATIBILITY_LEVEL = ' + CONVERT(NVARCHAR(100), @COMPAT) + N' WITH NO_WAIT;'
PRINT @SQL
EXEC(@SQL)
END
Brent says:the name comes from Netflix’s Chaos Monkey ,part of their open source Simian Army set of tools that will randomly break things in their AWS environment. They figure if they randomly take things down, it’ll force developers and admins to build a more reliable, tolerant infrastructure.