Random Hi Messages - 7 Actors

Generated by GenServerVirtualTime โ€ข Mermaid Flowchart

๐Ÿ“ˆ Simulation Summary

Virtual Time
3000ms
Real Time
3287850ms
Speedup
0.0x
Termination
โฑ Max Time

๐Ÿ“Š Actor Topology

flowchart LR alice("alice
๐Ÿ“ค Sent: 6469580
๐Ÿ“ฅ Recv: 6469496") bob("bob
๐Ÿ“ค Sent: 6467737
๐Ÿ“ฅ Recv: 6467671") charlie("charlie
๐Ÿ“ค Sent: 6468244
๐Ÿ“ฅ Recv: 6468190") diana("diana
๐Ÿ“ค Sent: 6470678
๐Ÿ“ฅ Recv: 6470630") eve("eve
๐Ÿ“ค Sent: 6470897
๐Ÿ“ฅ Recv: 6470855") frank("frank
๐Ÿ“ค Sent: 6468520
๐Ÿ“ฅ Recv: 6468484") grace("grace
๐Ÿ“ค Sent: 6468537
๐Ÿ“ฅ Recv: 6468507") bob -->|:hi
every 250ms| alice diana -->|:hi
every 350ms| alice charlie -->|:hi
every 300ms| alice bob -->|:hi
every 250ms| charlie eve -->|:hi
every 400ms| grace charlie -->|:hi
every 300ms| grace eve -->|:hi
every 400ms| charlie frank -->|:hi
every 450ms| bob charlie -->|:hi
every 300ms| frank bob -->|:hi
every 250ms| diana grace -->|:hi
every 500ms| frank grace -->|:hi
every 500ms| eve diana -->|:hi
every 350ms| eve grace -->|:hi
every 500ms| diana grace -->|:hi
every 500ms| bob diana -->|:hi
every 350ms| grace alice -->|:hi
every 200ms| eve grace -->|:hi
every 500ms| alice charlie -->|:hi
every 300ms| diana eve -->|:hi
every 400ms| bob eve -->|:hi
every 400ms| diana eve -->|:hi
every 400ms| frank alice -->|:hi
every 200ms| charlie bob -->|:hi
every 250ms| grace frank -->|:hi
every 450ms| eve alice -->|:hi
every 200ms| diana alice -->|:hi
every 200ms| grace charlie -->|:hi
every 300ms| eve bob -->|:hi
every 250ms| frank diana -->|:hi
every 350ms| charlie charlie -->|:hi
every 300ms| bob frank -->|:hi
every 450ms| alice eve -->|:hi
every 400ms| alice frank -->|:hi
every 450ms| diana alice -->|:hi
every 200ms| bob frank -->|:hi
every 450ms| grace diana -->|:hi
every 350ms| frank frank -->|:hi
every 450ms| charlie diana -->|:hi
every 350ms| bob grace -->|:hi
every 500ms| charlie alice -->|:hi
every 200ms| frank bob -->|:hi
every 250ms| eve style alice fill:#fff3e0,stroke:#f57c00,stroke-width:3px style bob fill:#fff3e0,stroke:#f57c00,stroke-width:3px style charlie fill:#fff3e0,stroke:#f57c00,stroke-width:3px style diana fill:#fff3e0,stroke:#f57c00,stroke-width:3px style eve fill:#fff3e0,stroke:#f57c00,stroke-width:3px style frank fill:#fff3e0,stroke:#f57c00,stroke-width:3px style grace fill:#fff3e0,stroke:#f57c00,stroke-width:3px

Node Shapes (Actor Type)

flowchart TD legend_processor("Processor
(send & receive)") style legend_processor fill:#ffffff,stroke:#666666,stroke-width:2px

Node Colors (Activity Level)

flowchart LR activity_0["๐ŸŸ  High Activity (>50 msgs)"] style activity_0 fill:#fff3e0,stroke:#f57c00,stroke-width:3px

๐Ÿ“‰ Detailed Statistics

Actor Sent Received Send Rate Receive Rate Activity
alice 6469580 6469496 2156526.67 msg/s 2156498.67 msg/s 12939076 total
bob 6467737 6467671 2155912.33 msg/s 2155890.33 msg/s 12935408 total
charlie 6468244 6468190 2156081.33 msg/s 2156063.33 msg/s 12936434 total
diana 6470678 6470630 2156892.67 msg/s 2156876.67 msg/s 12941308 total
eve 6470897 6470855 2156965.67 msg/s 2156951.67 msg/s 12941752 total
frank 6468520 6468484 2156173.33 msg/s 2156161.33 msg/s 12937004 total
grace 6468537 6468507 2156179.0 msg/s 2156169.0 msg/s 12937044 total
Summary: Total messages: 90568026 โ€ข Duration: 3000ms โ€ข Actors: 7

๐Ÿ’ป Model Source Code

This is the Elixir code that defines the actor simulation model:

# Create 7 actors that randomly send :hi messages to each other
# Using fixed random seed for reproducible results

# Set random seed for reproducibility
:rand.seed(:exs1024, {12_345, 67_890, 11_111})

# Create list of all actor names for random selection
all_actors = [:alice, :bob, :charlie, :diana, :eve, :frank, :grace]

# Function to randomly select a target (excluding self)
random_target = fn sender, targets ->
  available_targets = Enum.reject(targets, fn target -> target == sender end)
  if length(available_targets) > 0 do
    Enum.random(available_targets)
  else
    nil
  end
end

# Handler that sends random :hi messages
random_hi_handler = fn msg, state ->
  case msg do
    :hi ->
      # Randomly choose target and send :hi back
      target = random_target.(state.name, state.all_actors)
      if target do
        {:send, [{target, :hi}], state}
      else
        {:ok, state}
      end
    _ ->
      {:ok, state}
  end
end

simulation =
  ActorSimulation.new(trace: true)  # Enable tracing for sequence diagram
  |> ActorSimulation.add_actor(:alice,
    send_pattern: {:periodic, 200, :hi},
    targets: [:bob, :charlie, :diana, :eve, :frank, :grace],
    on_receive: random_hi_handler,
    initial_state: %{name: :alice, all_actors: all_actors}
  )
  |> ActorSimulation.add_actor(:bob,
    targets: [:alice, :charlie, :diana, :eve, :frank, :grace],
    on_receive: random_hi_handler,
    initial_state: %{name: :bob, all_actors: all_actors}
  )
  |> ActorSimulation.add_actor(:charlie,
    targets: [:alice, :bob, :diana, :eve, :frank, :grace],
    on_receive: random_hi_handler,
    initial_state: %{name: :charlie, all_actors: all_actors}
  )
  |> ActorSimulation.add_actor(:diana,
    targets: [:alice, :bob, :charlie, :eve, :frank, :grace],
    on_receive: random_hi_handler,
    initial_state: %{name: :diana, all_actors: all_actors}
  )
  |> ActorSimulation.add_actor(:eve,
    targets: [:alice, :bob, :charlie, :diana, :frank, :grace],
    on_receive: random_hi_handler,
    initial_state: %{name: :eve, all_actors: all_actors}
  )
  |> ActorSimulation.add_actor(:frank,
    targets: [:alice, :bob, :charlie, :diana, :eve, :grace],
    on_receive: random_hi_handler,
    initial_state: %{name: :frank, all_actors: all_actors}
  )
  |> ActorSimulation.add_actor(:grace,
    targets: [:alice, :bob, :charlie, :diana, :eve, :frank],
    on_receive: random_hi_handler,
    initial_state: %{name: :grace, all_actors: all_actors}
  )
  |> ActorSimulation.run(duration: 3000)  # Run for 3 seconds to get many interactions

# Generate sequence diagram
html = ActorSimulation.generate_sequence_diagram(simulation,
  title: "Random Hi Messages - 7 Actors",
  model_source: model_source
)