Member-only story
Performance Test: Low Memory
Sep 19, 2023
# on ec2 instance
sudo yum install -y gcc
gcc -o hog_mem_1210 hog_mem.c
./hog_mem_1210
# to experiment since resource usage can vary between instance types
# change the memory to hog e.g. 1210 to 1500
# compile e.g. gcc -o hog_mem_1500 hog_mem.c
# run ./hog_mem_1500
#include <stdlib.h>
#include <stdio.h>
int main() {
//1210 for c5.large
size_t memory_to_hog = 1210 * 1024 * 1024; // 1000 MB in bytes
char *memory = malloc(memory_to_hog);
if (memory == NULL) {
perror("Memory allocation failed");
return 1;
}
// Fill the allocated memory to prevent it from being optimized away
for (size_t i = 0; i < memory_to_hog; ++i) {
memory[i] = i % 256;
}
printf("Allocated %lu bytes of memory\n", memory_to_hog);
// Keep the program running indefinitely
while (1) {
}
return 0;
}