|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +use std::time::Instant; |
| 10 | + |
| 11 | +use criterion::BenchmarkId; |
| 12 | +use criterion::Criterion; |
| 13 | +use criterion::criterion_group; |
| 14 | +use criterion::criterion_main; |
| 15 | +use hyperactor_mesh::ProcMesh; |
| 16 | +use hyperactor_mesh::actor_mesh::ActorMesh; |
| 17 | +use hyperactor_mesh::actor_mesh::RootActorMesh; |
| 18 | +use hyperactor_mesh::alloc::AllocSpec; |
| 19 | +use hyperactor_mesh::alloc::Allocator; |
| 20 | +use hyperactor_mesh::alloc::LocalAllocator; |
| 21 | +use hyperactor_mesh::selection::dsl::all; |
| 22 | +use hyperactor_mesh::selection::dsl::true_; |
| 23 | +use hyperactor_mesh::shape; |
| 24 | + |
| 25 | +mod bench_actor; |
| 26 | +use bench_actor::BenchActor; |
| 27 | +use bench_actor::BenchMessage; |
| 28 | +use tokio::runtime::Runtime; |
| 29 | + |
| 30 | +// Benchmark how long does it take to process 1KB message on 1, 10, 100, 1K hosts with 8 GPUs each |
| 31 | +fn bench_actor_scaling(c: &mut Criterion) { |
| 32 | + let mut group = c.benchmark_group("actor_scaling"); |
| 33 | + let host_counts = vec![1, 10, 100, 1000]; |
| 34 | + let message_size = 1024; // Fixed message size (1KB) |
| 35 | + group.sample_size(10); |
| 36 | + group.sampling_mode(criterion::SamplingMode::Flat); |
| 37 | + |
| 38 | + for host_count in host_counts { |
| 39 | + group.bench_function(BenchmarkId::from_parameter(host_count), |b| { |
| 40 | + let mut b = b.to_async(Runtime::new().unwrap()); |
| 41 | + b.iter_custom(|iters| async move { |
| 42 | + let shape = shape! { hosts=host_count, gpus=8 }; |
| 43 | + let alloc = LocalAllocator |
| 44 | + .allocate(AllocSpec { |
| 45 | + shape: shape.clone(), |
| 46 | + constraints: Default::default(), |
| 47 | + }) |
| 48 | + .await |
| 49 | + .unwrap(); |
| 50 | + |
| 51 | + let proc_mesh = ProcMesh::allocate(alloc).await.unwrap(); |
| 52 | + let trainer_mesh: RootActorMesh<BenchActor> = |
| 53 | + proc_mesh.spawn("trainer", &()).await.unwrap(); |
| 54 | + let client = proc_mesh.client(); |
| 55 | + |
| 56 | + let start = Instant::now(); |
| 57 | + for i in 0..iters { |
| 58 | + let (tx, mut rx) = client.open_port(); |
| 59 | + let payload = vec![0u8; message_size]; |
| 60 | + |
| 61 | + trainer_mesh |
| 62 | + .cast( |
| 63 | + all(true_()), |
| 64 | + BenchMessage { |
| 65 | + step: i as usize, |
| 66 | + reply: tx.bind(), |
| 67 | + payload, |
| 68 | + }, |
| 69 | + ) |
| 70 | + .unwrap(); |
| 71 | + |
| 72 | + let mut msg_rcv = 0; |
| 73 | + while msg_rcv < host_count { |
| 74 | + let _ = rx.recv().await.unwrap(); |
| 75 | + msg_rcv += 1; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + start.elapsed() |
| 80 | + }); |
| 81 | + }); |
| 82 | + } |
| 83 | + |
| 84 | + group.finish(); |
| 85 | +} |
| 86 | + |
| 87 | +criterion_group!(benches, bench_actor_scaling); |
| 88 | +criterion_main!(benches); |
0 commit comments