Spex.InstanceManager.DistributedInstanceManager (spex v0.1.2)

Copy Markdown View Source

Instance manager that shards instances across multiple Spex.InstanceManager.Server processes.

This manager hashes each instance identifier and routes operations to one of several server shards. It is useful when you want to reduce contention versus a single-manager setup while preserving the same high-level API.

See Spex for info on using this instance manager.

Configuration

This manager accepts one distribution-specific option (:distribution_factor) plus server options forwarded to each shard (Spex.InstanceManager.Server.server_opt()).

  • :distribution_factor (pos_integer()) Number of server shards. Default: 4. Must be a positive integer; otherwise start_link/1 raises ArgumentError.

  • :dets_table is set per shard by this module (Spex.InstanceManager.DistributedInstanceManager.Server_<n>), so callers should not provide it.

  • For the other opts, see Spex.InstanceManager.SimpleInstanceManager

Routing semantics

Instance routing is deterministic:

  • hash = :erlang.phash2(instance_identifier)
  • shard index = rem(hash, distribution_factor) + 1

All operations for a given instance identifier are routed to the same shard.

Methods that aggregate globally (all_instances/0, all_instances/1, delete_instances/1, all_impl_models/0) query all shards and combine the results.

Summary

Functions

Functions

all_impl_models()

Callback implementation for Spex.InstanceManager.all_impl_models/0.

all_instances()

Callback implementation for Spex.InstanceManager.all_instances/0.

all_instances(specification)

Callback implementation for Spex.InstanceManager.all_instances/1.

child_spec(opts)

Callback implementation for Spex.InstanceManager.child_spec/1.

delete_instance(instance_identifier)

Callback implementation for Spex.InstanceManager.delete_instance/1.

delete_instances(filter_fun)

Callback implementation for Spex.InstanceManager.delete_instances/1.

export_impl_models()

Callback implementation for Spex.InstanceManager.export_impl_models/0.

get_instance(instance_identifier)

Callback implementation for Spex.InstanceManager.get_instance/1.

init_instance(spec, instance_identifier, meta \\ nil, initial_state \\ nil)

Callback implementation for Spex.InstanceManager.init_instance/4.

init_instance!(spec, instance_identifier, meta \\ nil, initial_state \\ nil)

Callback implementation for Spex.InstanceManager.init_instance!/4.

init_instance_async(spec, instance_identifier, meta \\ nil, initial_state \\ nil)

Callback implementation for Spex.InstanceManager.init_instance_async/4.

mock_instance!(spec, instance_identifier, state, meta \\ nil)

Callback implementation for Spex.InstanceManager.mock_instance!/4.

start_link(opts)

Callback implementation for Spex.InstanceManager.start_link/1.

transition(instance_identifier, action, state)

Callback implementation for Spex.InstanceManager.transition/3.

transition!(instance_identifier, action, state)

Callback implementation for Spex.InstanceManager.transition!/3.

transition_async(instance_identifier, action, state)

Callback implementation for Spex.InstanceManager.transition_async/3.