Skip to content

Commit

Permalink
[#189] Overall cleanup to move adapters to separate repos
Browse files Browse the repository at this point in the history
  • Loading branch information
cabol committed Mar 26, 2023
1 parent 15808aa commit 71618d5
Show file tree
Hide file tree
Showing 73 changed files with 1,420 additions and 8,434 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,11 @@ jobs:
if: ${{ matrix.style }}

- name: Run tests
run: |
epmd -daemon
mix test --trace
run: mix test
if: ${{ !matrix.coverage }}

- name: Run tests with coverage
run: |
epmd -daemon
mix coveralls.github
run: mix coveralls.github
if: ${{ matrix.coverage }}

- name: Run sobelow
Expand Down
67 changes: 24 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,49 @@ for more information.

## Usage

You need to add `nebulex` as a dependency to your `mix.exs` file. However, in
the case you want to use an external (a non built-in adapter) cache adapter,
you also have to add the proper dependency to your `mix.exs` file.

The supported caches and their adapters are:
You need to add both Nebulex and the cache adapter as a dependency to your
`mix.exs` file. The supported caches and their adapters are:

Cache | Nebulex Adapter | Dependency
:-----| :---------------| :---------
Generational Local Cache | [Nebulex.Adapters.Local][la] | Built-In
Partitioned | [Nebulex.Adapters.Partitioned][pa] | Built-In
Replicated | [Nebulex.Adapters.Replicated][ra] | Built-In
Multilevel | [Nebulex.Adapters.Multilevel][ma] | Built-In
Nil (special adapter that disables the cache) | [Nebulex.Adapters.Nil][nil] | Built-In
Generational Local Cache | Nebulex.Adapters.Local | [nebulex_adapters_local][la]
Partitioned | Nebulex.Adapters.Partitioned | [nebulex_adapters_partitioned][pa]
Replicated | Nebulex.Adapters.Replicated | [nebulex_adapters_replicated][ra]
Multilevel | Nebulex.Adapters.Multilevel | [nebulex_adapters_multilevel][ma]
Redis | NebulexRedisAdapter | [nebulex_redis_adapter][nbx_redis]
Cachex | Nebulex.Adapters.Cachex | [nebulex_adapters_cachex][nbx_cachex]
Distributed with Horde | Nebulex.Adapters.Horde | [nebulex_adapters_horde][nbx_horde]
Multilevel with cluster broadcasting | NebulexLocalMultilevelAdapter | [nebulex_local_multilevel_adapter][nbx_local_multilevel]

[la]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Local.html
[pa]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Partitioned.html
[ra]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Replicated.html
[ma]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Multilevel.html
[nil]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Nil.html
[la]: https://github.com/elixir-nebulex/nebulex_adapters_local
[pa]: https://github.com/elixir-nebulex/nebulex_adapters_partitioned
[ra]: https://github.com/elixir-nebulex/nebulex_adapters_replicated
[ma]: https://github.com/elixir-nebulex/nebulex_adapters_multilevel
[nbx_redis]: https://github.com/cabol/nebulex_redis_adapter
[nbx_cachex]: https://github.com/cabol/nebulex_adapters_cachex
[nbx_horde]: https://github.com/eliasdarruda/nebulex_adapters_horde
[nbx_local_multilevel]: https://github.com/slab/nebulex_local_multilevel_adapter

For example, if you want to use a built-in cache, add to your `mix.exs` file:
For example, if you want to use `Nebulex.Adapters.Local`, add to your `mix.exs`
file:

```elixir
def deps do
[
{:nebulex, "~> 2.4"},
{:shards, "~> 1.0"}, #=> When using :shards as backend
{:decorator, "~> 1.4"}, #=> When using Caching Annotations
{:telemetry, "~> 1.0"} #=> When using the Telemetry events (Nebulex stats)
{:nebulex, "~> 3.0"},
{:nebulex_adapters_local, "~> 3.0"},
{:decorator, "~> 1.4"}, #=> When using Caching Annotations
{:telemetry, "~> 1.0"}, #=> When using the Telemetry events (Nebulex stats)
{:shards, "~> 1.0"}, #=> When using :shards as backend
]
end
```

In order to give more flexibility and fetch only needed dependencies, Nebulex
makes all dependencies optional. For example:

* For intensive workloads, you may want to use `:shards` as the backend for
the local adapter and having partitioned tables. In such a case, you have
to add `:shards` to the dependency list.

* For enabling the usage of
[declarative annotation-based caching via decorators][nbx_caching],
you have to add `:decorator` to the dependency list.
Expand All @@ -90,8 +85,9 @@ makes all dependencies optional. For example:
you have to add `:telemetry` to the dependency list.
See [telemetry guide][telemetry].

* If you want to use an external adapter (e.g: Cachex or Redis adapter), you
have to add the adapter dependency too.
* For intensive workloads, you may want to use `:shards` as the backend for
the local adapter and having partitioned tables. In such a case, you have
to add `:shards` to the dependency list.

[telemetry]: http://hexdocs.pm/nebulex/telemetry.html

Expand Down Expand Up @@ -236,27 +232,12 @@ the directory [benchmarks](./benchmarks).
To run a benchmark test you have to run:

```
$ MIX_ENV=test mix run benchmarks/{BENCH_TEST_FILE}
$ mix run benchmarks/benchmark.exs
```

Where `BENCH_TEST_FILE` can be any of:

* `local_with_ets_bench.exs`: benchmark for the local adapter using
`:ets` backend.
* `local_with_shards_bench.exs`: benchmark for the local adapter using
`:shards` backend.
* `partitioned_bench.exs`: benchmark for the partitioned adapter.

For example, for running the benchmark for the local adapter using `:shards`
backend:

```
$ MIX_ENV=test mix run benchmarks/local_with_shards_bench.exs
```

Additionally, you can also run performance tests using `:basho_bench`.
See [nebulex_bench example](https://github.com/cabol/nebulex_examples/tree/master/nebulex_bench)
for more information.
> The benchmark uses the adapter `Nebulex.Adapters.Nil`; it is more focused on
> measuring the Nebulex abstraction layer performance rather than a specific
> adapter.
## Contributing

Expand Down
77 changes: 0 additions & 77 deletions benchmarks/bench_helper.exs

This file was deleted.

77 changes: 77 additions & 0 deletions benchmarks/benchmark.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
## Benchmarks

:ok = Application.start(:telemetry)

defmodule Cache do
@moduledoc false
use Nebulex.Cache,
otp_app: :nebulex,
adapter: Nebulex.Adapters.Nil
end

benchmarks = %{
"get" => fn input ->
Cache.get(input)
end,
"get_all" => fn input ->
Cache.get_all([input, "foo", "bar"])
end,
"put" => fn input ->
Cache.put(input, input)
end,
"put_new" => fn input ->
Cache.put_new(input, input)
end,
"replace" => fn input ->
Cache.replace(input, input)
end,
"put_all" => fn input ->
Cache.put_all([{input, input}, {"foo", "bar"}])
end,
"delete" => fn input ->
Cache.delete(input)
end,
"take" => fn input ->
Cache.take(input)
end,
"has_key?" => fn input ->
Cache.has_key?(input)
end,
"count_all" => fn _input ->
Cache.count_all()
end,
"ttl" => fn input ->
Cache.ttl(input)
end,
"expire" => fn input ->
Cache.expire(input, 1)
end,
"incr" => fn _input ->
Cache.incr(:counter, 1)
end,
"update" => fn input ->
Cache.update(input, 1, &Kernel.+(&1, 1))
end,
"all" => fn _input ->
Cache.all()
end
}

# start local cache
{:ok, local} = Cache.start_link()

Benchee.run(
benchmarks,
inputs: %{"rand" => 100_000},
before_each: fn n -> :rand.uniform(n) end,
formatters: [
{Benchee.Formatters.Console, comparison: false, extended_statistics: true},
{Benchee.Formatters.HTML, extended_statistics: true, auto_open: false}
],
print: [
fast_warning: false
]
)

# stop cache
if Process.alive?(local), do: Supervisor.stop(local)
21 changes: 0 additions & 21 deletions benchmarks/local_with_ets_bench.exs

This file was deleted.

21 changes: 0 additions & 21 deletions benchmarks/local_with_shards_bench.exs

This file was deleted.

22 changes: 0 additions & 22 deletions benchmarks/partitioned_bench.exs

This file was deleted.

Loading

0 comments on commit 71618d5

Please sign in to comment.