Sanket Achari
Sanket Achari

Reputation: 500

How to get available processors in elixir?

In java available processors can be obtained by calling

Runtime.getRuntime().availableProcessors()

What is the corresponding api in elixir?

Upvotes: 0

Views: 661

Answers (2)

bitwalker
bitwalker

Reputation: 9251

The Elixir way of doing it is System.schedulers/0 or System.schedulers_online/0, where the former is the total number of schedulers, and the latter is the total number of schedulers which are active (i.e., actually being used)

Upvotes: 2

Michael Oliver
Michael Oliver

Reputation: 1412

The :erlang module provides this information with a system_info call:

:erlang.system_info(:schedulers_online)

Erlang abstracts CPUs away as "schedulers", and this API allows you to query how many are available.

Upvotes: 1

Related Questions