Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple Memory loader in Python for Kebernetes GKE
FROM python:3.5-alpine
ADD https://gist.githubusercontent.com/haizaar/607f43e282c4e0f8737a/raw/1145c89b5aa34e2ec7afe32fb9d0e27661c7debd/mem_loader.pyy mem_loader.py
CMD python -u mem_loader.py
apiVersion: v1
kind: Pod
metadata:
name: mem-large
spec:
containers:
- image: docker.io/haizaar/mem-loader:1.2
name: mem-large
resources:
requests:
memory: "2500Mi"
limits:
memory: "2500Mi"
env:
- name: MAXMEM
value: "2147483648"
apiVersion: v1
kind: Pod
metadata:
name: mem-small
spec:
containers:
- image: docker.io/haizaar/mem-loader:1.2
name: mem-small
resources:
requests:
memory: "100Mi"
limits:
memory: "100Mi"
env:
- name: MAXMEM
value: "2147483648"
import os
import sys
import signal
PAGE_SIZE_IN_K = 4
KILO = 1024
MAXMEM = int(os.environ.get("MAXMEM", 2 * 2**30))
def get_memory_usage():
return int(open("/proc/self/statm", "rt").read().split()[1]) * PAGE_SIZE_IN_K * KILO
def bloat():
l = []
mem_usage = 0
while mem_usage < MAXMEM:
l.append(b"a" * 1000000)
mem_usage = get_memory_usage()
sys.stderr.write("Reached %d megabytes\n" % (mem_usage/2**20))
return l
if __name__ == "__main__":
mem = bloat()
signal.pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment