├── .gitignore ├── 1024m └── Dockerfile ├── 2cpu1024m └── Dockerfile ├── 2cpu256m └── Dockerfile ├── 2cpu512m └── Dockerfile ├── 512m └── Dockerfile ├── Dockerfile ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/vim,linux,macos,windows 3 | 4 | ### Linux ### 5 | *~ 6 | 7 | # temporary files which can be created if a process still has a handle open of a deleted file 8 | .fuse_hidden* 9 | 10 | # KDE directory preferences 11 | .directory 12 | 13 | # Linux trash folder which might appear on any partition or disk 14 | .Trash-* 15 | 16 | # .nfs files are created when an open file is removed but is still being accessed 17 | .nfs* 18 | 19 | ### macOS ### 20 | *.DS_Store 21 | .AppleDouble 22 | .LSOverride 23 | 24 | # Icon must end with two \r 25 | Icon 26 | 27 | # Thumbnails 28 | ._* 29 | 30 | # Files that might appear in the root of a volume 31 | .DocumentRevisions-V100 32 | .fseventsd 33 | .Spotlight-V100 34 | .TemporaryItems 35 | .Trashes 36 | .VolumeIcon.icns 37 | .com.apple.timemachine.donotpresent 38 | 39 | # Directories potentially created on remote AFP share 40 | .AppleDB 41 | .AppleDesktop 42 | Network Trash Folder 43 | Temporary Items 44 | .apdisk 45 | 46 | ### Vim ### 47 | # swap 48 | [._]*.s[a-v][a-z] 49 | [._]*.sw[a-p] 50 | [._]s[a-v][a-z] 51 | [._]sw[a-p] 52 | # session 53 | Session.vim 54 | # temporary 55 | .netrwhist 56 | # auto-generated tag files 57 | tags 58 | 59 | ### Windows ### 60 | # Windows thumbnail cache files 61 | Thumbs.db 62 | ehthumbs.db 63 | ehthumbs_vista.db 64 | 65 | # Folder config file 66 | Desktop.ini 67 | 68 | # Recycle Bin used on file shares 69 | $RECYCLE.BIN/ 70 | 71 | # Windows Installer files 72 | *.cab 73 | *.msi 74 | *.msm 75 | *.msp 76 | 77 | # Windows shortcuts 78 | *.lnk 79 | 80 | # End of https://www.gitignore.io/api/vim,linux,macos,windows 81 | 82 | -------------------------------------------------------------------------------- /1024m/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bretfisher/stress:latest 2 | 3 | CMD ["stress", "--verbose", "--vm", "1", "--vm-bytes", "1024M"] 4 | -------------------------------------------------------------------------------- /2cpu1024m/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bretfisher/stress:latest 2 | 3 | CMD ["stress", "--verbose", "--vm", "2", "--vm-bytes", "1024M"] 4 | -------------------------------------------------------------------------------- /2cpu256m/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bretfisher/stress:latest 2 | 3 | CMD ["stress", "--verbose", "--vm", "2", "--vm-bytes", "256M"] 4 | -------------------------------------------------------------------------------- /2cpu512m/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bretfisher/stress:latest 2 | 3 | CMD ["stress", "--verbose", "--vm", "2", "--vm-bytes", "512M"] 4 | -------------------------------------------------------------------------------- /512m/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bretfisher/stress:latest 2 | 3 | CMD ["stress", "--verbose", "--vm", "1", "--vm-bytes", "512M"] 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:latest 2 | 3 | RUN apt-get update && apt-get install -y stress \ 4 | --no-install-recommends && rm -r /var/lib/apt/lists/* 5 | 6 | CMD ["stress", "--verbose", "--vm", "1", "--vm-bytes", "256M"] 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2015-2017 Bret Fisher 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Easy CPU and Memory Stressing for Docker and SwarmKit 2 | 3 | There's lots of images/repos using `stress` or `stress-ng` but I needed something 4 | that didn't need a custom ENTRYPOINT/CMD to work so it was easy to demo with 5 | `docker service create`, so here we go: 6 | 7 | > Simply running this image with various tags will get you pre-set cpu/memory stressing output. 8 | 9 | | Image:Tag | Command | 10 | | --------- | ------- | 11 | | `bretfisher/stress:latest` | `stress --verbose --vm 1 --vm-bytes 256M` | 12 | | `bretfisher/stress:256m` | `stress --verbose --vm 1 --vm-bytes 256M` | 13 | | `bretfisher/stress:512m` | `stress --verbose --vm 1 --vm-bytes 512M` | 14 | | `bretfisher/stress:1024m` | `stress --verbose --vm 1 --vm-bytes 1024M` | 15 | | `bretfisher/stress:2cpu256m` | `stress --verbose --vm 2 --vm-bytes 256M` | 16 | | `bretfisher/stress:2cpu512m` | `stress --verbose --vm 2 --vm-bytes 512M` | 17 | | `bretfisher/stress:2cpu1024m` | `stress --verbose --vm 2 --vm-bytes 1024M` | 18 | 19 | ## Example 20 | 21 | 22 | Notice that the task will crash so quickly that it won't "finish" deployment. 23 | 24 | ```bash 25 | docker service create --limit-memory 200M bretfisher/stress:512m 26 | w5656w2kynqt4xip0b321d91y 27 | overall progress: 0 out of 1 tasks 28 | 1/1: ready [======================================> ] 29 | verify: Detected task failure 30 | Operation continuing in background. 31 | Use `docker service ps w5656w2kynqt4xip0b321d91y` to check progress. 32 | ``` 33 | 34 | If I looked at the replica list, you'll see Swarm shutting down out-of-memory tasks and starting new ones 35 | 36 | 37 | ```bash 38 | docker service ps w5 39 | ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 40 | zkvjxdl7o7ej suspicious_lamport.1 bretfisher/stress:512m linuxkit-025000000001 Shutdown Failed about a minute ago "task: non-zero exit (1)" 41 | xtvjqeh190z2 \_ suspicious_lamport.1 bretfisher/stress:512m linuxkit-025000000001 Shutdown Failed 2 minutes ago "task: non-zero exit (1)" 42 | yv7eoc5c7n2z \_ suspicious_lamport.1 bretfisher/stress:512m linuxkit-025000000001 Shutdown Failed 2 minutes ago "task: non-zero exit (1)" 43 | xyutkbaajjc1 \_ suspicious_lamport.1 bretfisher/stress:512m linuxkit-025000000001 Shutdown Failed 4 minutes ago "task: non-zero exit (1)" 44 | ``` 45 | 46 | 47 | If I looked at service logs for just one of those tasks, you'd see it start, consume memory, then crash 48 | 49 | 50 | ```bash 51 | docker service logs w5 2>&1 | grep yv7eoc5c7n2z 52 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd 53 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: dbug: [1] using backoff sleep of 3000us 54 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: dbug: [1] --> hogvm worker 1 [7] forked 55 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: dbug: [7] allocating 536870912 bytes ... 56 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: dbug: [7] touching bytes in strides of 4096 bytes ... 57 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: FAIL: [1] (415) <-- worker 7 got signal 9 58 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: WARN: [1] (417) now reaping child worker processes 59 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: FAIL: [1] (421) kill error: No such process 60 | suspicious_lamport.1.yv7eoc5c7n2z@linuxkit-025000000001 | stress: FAIL: [1] (451) failed run completed in 1s 61 | ``` 62 | 63 | 64 | If I was watching `docker events` I'd see it create the container, start it, have a oom event, then die 65 | 66 | - ~ container create ~ 67 | - ~ network create ~ 68 | - ~ container start ~ 69 | - ~ container oom ~ 70 | - ~ container die ~ 71 | - ~ network disconnect ~ 72 | - ~ container destroy ~ 73 | --------------------------------------------------------------------------------