Loads IP-to-ASN data for Limen.Signal.Asn and keeps it current, off the
request path.
Loading
At startup the loader reads the :file of the :asn configuration, if it
exists. Each table (see Limen.Signal.Asn.Table) is built in a
short-lived process, so the memory building takes goes with it, and is
complete before it replaces the published one: lookups see the old table
or the new one, never a partial load. load/2 and load_rows/2 load other
data by hand.
Refreshing
With a :url, the loader downloads the data into :file and checks it
for changes on the schedule of the :refresh options (see
Limen.Signal.Asn.Schedule and Limen.Config):
- a check downloads the data only if it changed since the file was last confirmed current, which restarting does not reset;
- a scheduled check is postponed while the BEAM's schedulers are busier
than
:max_utilization(sampled for a second) or its memory is above:max_memory: building a table takes a few seconds of one scheduler and, for the full iptoasn.com data, about 100 MB for that time; - new data with less than half the ranges of the loaded table is rejected as a broken download, and so is data with no range at all;
- a failed check keeps the current data and is retried with backoff.
refresh/1 checks at once, whatever the schedule and the load, and
status/1 reports what the loader did and plans to do. Every load and
check emits telemetry, see Limen.Telemetry.
Summary
Functions
Returns a specification to start this module under a supervisor.
Loads an iptoasn.com TSV file (optionally gzipped) into instance.
Loads ranges given as {first, last, asn, country, name} tuples into
instance. Meant for tests and small custom tables.
Checks the :url for new data now, whatever the schedule and the load,
and reschedules the next check from there.
What instance has loaded and when it checks next.
The share of time the BEAM's schedulers were busy over the next ms
milliseconds, between 0.0 and 1.0.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec load(atom(), Path.t()) :: {:ok, non_neg_integer()} | {:error, term()}
Loads an iptoasn.com TSV file (optionally gzipped) into instance.
Returns the number of ranges loaded.
@spec load_rows(atom(), [Limen.Signal.Asn.Table.row()]) :: {:ok, non_neg_integer()} | {:error, term()}
Loads ranges given as {first, last, asn, country, name} tuples into
instance. Meant for tests and small custom tables.
Checks the :url for new data now, whatever the schedule and the load,
and reschedules the next check from there.
What instance has loaded and when it checks next.
:ranges,:bytes,:loaded_atand:sourcedescribe the loaded table, or arenilwhen none is;:next_checkis when the next check is due, in milliseconds since the epoch, ornilwithout a:url;:last_checkis%{at: milliseconds, result: result}, ornil;:failurescounts consecutive failed checks.
The loader answers once it finishes what it is doing, which can be a
download; pass a timeout in milliseconds to wait less.
@spec utilization(pos_integer()) :: float()
The share of time the BEAM's schedulers were busy over the next ms
milliseconds, between 0.0 and 1.0.