Skip to content

4.3 GenServer summary

This is a list of GenServer process support aggregate data.

  • ASIC Mining Rig Index:

  • ASIC Mining Rig Historical Index: the same as ASIC Mining Rig Index but store in array.

  • CPU/GPU Mining Rig Index:

    • store latest stats of all mining rig including: hashrate, algo., power consumption, temperature.
    • store aggregated indexs of all mining rig including: total hashrate by algo, total power consumption.

Why do we need extra layer of data, DB is enough?

Due to remove/update stats feature (asic/cpu/gpu) & aggregate indexs, there will be many READ operation from database. Plus, there are many many operational logs sending to the Commander. Even though, we have message queue, but the pressure is real for one single database.

This is a scenerio that we use extra layer, we want to render asic mining rig index page with aggregated number such as total hashrate. (1) We need to query the db for all available asic. ( condition less than 30-second-ping alive) (2) Sum all the hashrate If we have new operational data inserted into database, to calculate the total hashrate, we then need to start over from step (1).

1. ASIC Miner Operational Index

  • ASIC Mining Rig Index, the GenServer should be named AsicMinerOperationalIndex, it stores data in a map. The key is asic_miner_id, and value is AsicMinerLog.
  • Found source code here: github link

Beside storing latest state, AsicMiningRigIndex GenServer also can do:

  • remove old operational data. An asic with latest record is older than current timestamp by 1 minutes should be remove. The asic is consider offline/dead.
  • when the AsicMinerOperationalIndex get update, AsicMiningRigIndex GenServer will do broadcast (NOT IMMEDIATELY) to pubsub channel named:
    • asic_miner_index
    • asic_miner_aggregated_index
    • The main reason that AsicMinerOperationalIndex does not broadcast instantly, it will spam the socket channel from commander to web browser.

GenServer-AsicMinerOperationalIndex's state example:

%{
    asic_miner_id => %AsicMinerLog{}
}

In addition, each one second, this GenServer-AsicMinerOperationalIndex will broadcast operational data. This is an example:

%{
      asic_miner_map: %{asic_miner_id => %AsicMiner{} },
      asic_miner_operational_map: %{asic_miner_id => %AsicMinerLog{} },
      asic_miner_aggregated_index: %{
          coin_hashrate_map: %{"Bitcoin" => {120, "TH/s"},
                               "Kaspa" => {20, "TH/s"}
                              },
          total_power: 7000,
          asic_miner_alive: "2/3"
      }
}

2. CPU/GPU Miner Operational Index

  • The GenServer named CpuGpuMinerOperationalIndex
  • Main features:
    • Broadcast operational data which then be used for cpu/gpu miner index page.
    • Nillify offline miner if operational data is older than 60 seconds.
  • The state example:
%{
    cpu_gpu_miner_id => %CpuGpuMinerLog{}
}
  • Broadcast payload example:
%{
  cpu_gpu_miner_map: %{cpu_gpu_miner_id => %CpuGpuMiner{}} ,
  cpu_gpu_miner_operational_map: %{cpu_gpu_miner_id => %CpuGpuMinerLog{}},
  aggregated_index: %{
    total_power: total_power,
    cpu_gpu_miner_alive: cpu_gpu_miner_alive,
    coin_hashrate_map: %{
                         "Monero" => {12, "KH/s"},
                         "Ergo" => {12, "MH/s"},
                        }
  }
}