import time
import sys
import random
import hashlib
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
def compute_hashes(data):
result = []
for item in data:
hash_obj = hashlib.sha256(str(item).encode())
result.append(hash_obj.hexdigest())
return result
def mixed_workload(duration_seconds=60):
print(f"Starting mixed workload for {duration_seconds} seconds...")
print(f"Job ID: {sys.argv[0]}")
start_time = time.time()
data_store = []
computation_count = 0
iteration = 0
while time.time() - start_time < duration_seconds:
iteration += 1
elapsed = time.time() - start_time
if iteration % 2 == 0:
chunk = [random.random() for _ in range(100_000)]
data_store.append(chunk)
if len(data_store) > 10:
data_store.pop(0)
memory_mb = (sum(len(c) for c in data_store) * 8) / (1024 * 1024)
print(f"[{elapsed:.1f}s] Memory phase: {len(data_store)} chunks, "
f"~{memory_mb:.1f} MB")
else:
fib_results = []
for n in range(25, 31): fib_results.append(fibonacci(n))
computation_count += len(fib_results)
if data_store:
chunk_idx = random.randint(0, len(data_store) - 1)
sample_data = data_store[chunk_idx][:100]
hashes = compute_hashes(sample_data)
print(f"[{elapsed:.1f}s] CPU phase: computed {len(fib_results)} Fibonacci numbers, "
f"largest: {fib_results[-1]:,}")
time.sleep(0.5)
elapsed = time.time() - start_time
total_memory_elements = sum(len(c) for c in data_store)
memory_mb = (total_memory_elements * 8) / (1024 * 1024)
print(f"\nCompleted in {elapsed:.2f} seconds")
print(f"Total iterations: {iteration}")
print(f"Computation count: {computation_count}")
print(f"Final data chunks: {len(data_store)}")
print(f"Final memory usage: ~{memory_mb:.1f} MB")
return iteration
if __name__ == "__main__":
try:
iterations = mixed_workload(60)
print(f"\n✓ Mixed workload job completed successfully")
sys.exit(0)
except Exception as e:
print(f"\n✗ Error: {e}", file=sys.stderr)
sys.exit(1)