You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-57Lines changed: 75 additions & 57 deletions
Original file line number
Diff line number
Diff line change
@@ -5,25 +5,29 @@
5
5
6
6
ETS tables on steroids!
7
7
8
-
[**Shards**](https://github.com/cabol/shards) is an **Erlang/Elixir** library/tool compatible with the ETS API,
9
-
that implements [Sharding/Partitioning](https://en.wikipedia.org/wiki/Partition_(database)) support on top of
10
-
ETS totally transparent and out-of-box. **Shards** might be probably the **simplest** option to scale-out ETS tables.
8
+
[**Shards**](https://github.com/cabol/shards) is an **Erlang/Elixir** library/tool
9
+
compatible with the ETS API, that implements [Sharding/Partitioning](https://en.wikipedia.org/wiki/Partition_(database)) support
10
+
on top of ETS totally transparent and out-of-box. **Shards** might be probably
11
+
the **simplest** option to scale-out ETS tables.
11
12
12
13
[Additional documentation on cabol.github.io](http://cabol.github.io/posts/2016/04/14/sharding-support-for-ets.html).
13
14
14
15
15
16
## Introduction
16
17
17
-
Why might we need **Sharding** on ETS tables? Well, the main reason is to keep the lock contention under control,
18
-
in order to scale-out ETS tables (linearly) and support higher levels of concurrency without lock issues
19
-
(specially write-locks) – which most of the cases might cause significant performance degradation.
18
+
Why might we need **Sharding** on ETS tables? Well, the main reason is to keep
19
+
the lock contention under control, in order to scale-out ETS tables (linearly)
20
+
and support higher levels of concurrency without lock issues; specially
21
+
write-locks – which most of the cases might cause significant performance
22
+
degradation.
20
23
21
-
Therefore, one of the most common and proven strategies to deal with these problems is [Sharding/Partitioning](https://en.wikipedia.org/wiki/Partition_(database))
22
-
– the principle is pretty similar to [DHTs](https://en.wikipedia.org/wiki/Distributed_hash_table).
24
+
Therefore, one of the most common and proven strategies to deal with these problems
25
+
is [Sharding/Partitioning](https://en.wikipedia.org/wiki/Partition_(database)) –
26
+
the principle is pretty similar to [DHTs](https://en.wikipedia.org/wiki/Distributed_hash_table).
23
27
24
-
Here is where **Shards** comes in. **Shards** makes it extremely easy to achieve all this, with **zero** effort.
25
-
It provides an API compatible with [ETS](http://erlang.org/doc/man/ets.html) – with few exceptions.
26
-
You can check the list of compatible ETS functions that **Shards** provides [HERE](https://github.com/cabol/shards/issues/1).
28
+
Here is where **Shards** comes in. **Shards** makes it extremely easy to achieve
29
+
all this, with **zero** effort. It provides an API compatible with [ETS](http://erlang.org/doc/man/ets.html) – with few exceptions. You can check
30
+
the list of compatible ETS functions that **Shards** provides [HERE](https://github.com/cabol/shards/issues/1).
27
31
28
32
29
33
## Usage
@@ -34,7 +38,7 @@ In your `rebar.config`:
34
38
35
39
```erlang
36
40
{deps, [
37
-
{shards, "0.4.3"}
41
+
{shards, "0.4.4"}
38
42
]}.
39
43
```
40
44
@@ -80,8 +84,8 @@ Option | Description | Default
80
84
`{n_shards, pos_integer()}` | Allows to set the desired number of shards. | By default, the number of shards is calculated from the total online schedulers: `erlang:system_info(schedulers_online)`
81
85
`{scope, l | g}` | Defines `shards` scope, in other words, if sharding will be applied locally (`l`) or global/distributed (`g`) | `l`
82
86
`{restart_strategy, one_for_one | one_for_all}` | Allows to configure the restart strategy for `shards_owner_sup`. | `one_for_one`
83
-
`{pick_shard_fun, pick_fun()}` | Function to pick the **shard** on which the `key` will be handled locally – used by `shards_local`. See [shards_state](./src/shards_state.erl). | `shards_local:pick/3`
84
-
`{pick_node_fun, pick_fun()}` | Function to pick the **node** on which the `key` will be handled globally/distributed – used by `shards_dist`. See [shards_state](./src/shards_state.erl). | `shards_local:pick/3`
87
+
`{pick_shard_fun, pick_fun()}` | Function to pick the **shard** on which the `key` will be handled locally – used by `shards_local`. See [shards_state](./src/shards_state.erl). | `shards_lib:pick/3`
88
+
`{pick_node_fun, pick_fun()}` | Function to pick the **node** on which the `key` will be handled globally/distributed – used by `shards_dist`. See [shards_state](./src/shards_state.erl). | `shards_lib:pick/3`
85
89
`{nodes, [node()]}` | Allows to set a list of nodes to auto setup a distributed table – the table is created in all given nodes and then all nodes are joined. This option only has effect if the option `{scope, g}` has been set. | `[]`
86
90
`{sup_name, atom()}` | Allows to define a custom name for `shards_sup`. | `shards_sup`
87
91
@@ -124,10 +128,11 @@ mytab2
124
128
ok
125
129
```
126
130
127
-
You will see the process tree of `shards` application. When you create a new "table," what happens behind
128
-
is: `shards` creates a supervision tree dedicated only to that group of shards that will represent
129
-
your logical table in multiple physical ETS tables and everything is handled auto-magically by `shards`,
130
-
you only have to use the API like if you were working with a common ETS table.
131
+
You will see the process tree of `shards` application. When you create a new "table,"
132
+
what happens behind is: `shards` creates a supervision tree dedicated only to that
133
+
group of shards that will represent your logical table in multiple physical ETS
134
+
tables and everything is handled auto-magically by `shards`, you only have to use
135
+
the API like if you were working with a common ETS table.
131
136
132
137
### Playing with shards
133
138
@@ -181,8 +186,8 @@ See how `shards` gets shrinks.
181
186
182
187
## State
183
188
184
-
In the previous section we saw something about the `state`, how it can be fetched at any time.
185
-
But, what is the `state`?
189
+
In the previous section we saw something about the `state`, how it can be fetched
190
+
at any time. But, what is the `state`?
186
191
187
192
There are different properties that have to be stored somewhere for `shards` to work
188
193
correctly. Remember, `shards` has a logic on top of `ETS`, for example, compute the
@@ -198,11 +203,11 @@ The `shards` state is defined as:
0 commit comments