Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify pool config - part 1 #2077

Merged
merged 17 commits into from Sep 19, 2018
Merged

Unify pool config - part 1 #2077

merged 17 commits into from Sep 19, 2018

Conversation

michalwski
Copy link
Contributor

This PR makes it possible to start following pools:

  • redis
  • riak
  • cassandra
  • http
  • generic (used in sns, and push modules)

via outgoing_pools config option as described in #1959. The issue is not full covered by this PR yet. Remaining work relates to rdbms and elasticsearch pools.

Currently big_tests starts only riak and cassandra pools via the outgoing_pools option. Other pools while possible to start in this way are still started directly by modules using them.

@mongoose-im
Copy link
Collaborator

mongoose-im commented Sep 14, 2018

5581.1 / Erlang 19.3 / small_tests / 0c56fcf
Reports root / small


5581.3 / Erlang 19.3 / mysql_redis / 0c56fcf
Reports root/ big
OK: 2832 / Failed: 0 / User-skipped: 222 / Auto-skipped: 0


5581.6 / Erlang 19.3 / elasticsearch_and_cassandra_mnesia / 0c56fcf
Reports root/ big
OK: 445 / Failed: 0 / User-skipped: 8 / Auto-skipped: 0


5581.5 / Erlang 19.3 / ldap_mnesia / 0c56fcf
Reports root/ big
OK: 1032 / Failed: 0 / User-skipped: 80 / Auto-skipped: 0


5581.2 / Erlang 19.3 / internal_mnesia / 0c56fcf
Reports root/ big
OK: 1067 / Failed: 0 / User-skipped: 45 / Auto-skipped: 0


5581.4 / Erlang 19.3 / odbc_mssql_mnesia / 0c56fcf
Reports root/ big
OK: 2846 / Failed: 0 / User-skipped: 208 / Auto-skipped: 0


5581.9 / Erlang 21.0 / riak_mnesia / 0c56fcf
Reports root/ big / small
OK: 1290 / Failed: 0 / User-skipped: 43 / Auto-skipped: 0


5581.8 / Erlang 20.0 / pgsql_mnesia / 0c56fcf
Reports root/ big / small
OK: 2878 / Failed: 0 / User-skipped: 176 / Auto-skipped: 0

@michalwski michalwski closed this Sep 17, 2018
@michalwski michalwski reopened this Sep 17, 2018
@mongoose-im
Copy link
Collaborator

mongoose-im commented Sep 17, 2018

5590.1 / Erlang 19.3 / small_tests / a1132a5
Reports root / small


5590.2 / Erlang 19.3 / internal_mnesia / a1132a5
Reports root/ big
OK: 1067 / Failed: 0 / User-skipped: 45 / Auto-skipped: 0


5590.4 / Erlang 19.3 / odbc_mssql_mnesia / a1132a5
Reports root/ big
OK: 2846 / Failed: 0 / User-skipped: 208 / Auto-skipped: 0


5590.6 / Erlang 19.3 / elasticsearch_and_cassandra_mnesia / a1132a5
Reports root/ big
OK: 445 / Failed: 0 / User-skipped: 8 / Auto-skipped: 0


5590.5 / Erlang 19.3 / ldap_mnesia / a1132a5
Reports root/ big
OK: 1032 / Failed: 0 / User-skipped: 80 / Auto-skipped: 0


5590.3 / Erlang 19.3 / mysql_redis / a1132a5
Reports root/ big
OK: 2832 / Failed: 0 / User-skipped: 222 / Auto-skipped: 0


5590.8 / Erlang 20.0 / pgsql_mnesia / a1132a5
Reports root/ big / small
OK: 2878 / Failed: 0 / User-skipped: 176 / Auto-skipped: 0


5590.9 / Erlang 21.0 / riak_mnesia / a1132a5
Reports root/ big / small
OK: 1290 / Failed: 0 / User-skipped: 43 / Auto-skipped: 0

@@ -0,0 +1,107 @@
# Outgoing connections

MongooseIM can be cofigured to talk to external service like databases or HTTP servers in order get or set required data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configured
I'm gonna leave the actual language check to @goddammit ;)

* `strategy` - specifies worker selection strategy for the given pool, default is `best_worker`,
more details on this can be found in [Choosing strategy in worker_pool doc](https://github.com/inaka/worker_pool#choosing-a-strategy)
* `call_timeout` - specifies the timeout for a call operation to the pool
* `ConnectionOptions` - list of `{key, value}` pairs passed to the `start` function of the pool type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not always, e.g. a tuple configuring Riak connection's SSL has 3 elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@@ -51,8 +51,9 @@ start(Host, Opts) ->

MaxHTTPConnections = gen_mod:get_opt(max_http_connections, Opts, 100),
mongoose_wpool:ensure_started(),
{ok, _} = mongoose_wpool:start(?MODULE, Host, [{strategy, available_worker},
{workers, MaxHTTPConnections}]),
{ok, _} = mongoose_wpool:start(generic, Host, mod_push,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of dislike replacing ?MODULE with tags that are meant to reference the module but in a subtler way. If we see a pool process with e.g. pusher_push in its name, we'll grep around the code to find where it comes from. If the tag was simply ?MODULE, everything would be clear from the getgo. In this instance, mod_push does not really correspond to a pool for mongoosepush service.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Previously ?MODULE was used as the pool's type which doesn't fit nicely to the convention introduced and explained in Worker pool unification, iteration 2 #1959.
  2. On one hand using ?MODULE as a tag name would be handy, on the other hand in the future the tag name is supposed to be configurable, which makes greping even more difficult.
  3. I'm ok with using ?MODULE as a tag for pool which are not started via outgoing_pools option.

@fenek I think your input on this is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with merging this as-is if we only change the mod_push tag to something a little more fitting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, is it any better now @kzemek?

RiakPBOpts = [auto_reconnect, keepalive],
WorkerArgs = maybe_add_additional_opts(RiakPBOpts, SecurityOpts),
Worker = {riakc_pb_socket, [RiakAddr, RiakPort, WorkerArgs]},
{_, Workers} = mongoose_wpool_riak:get_riak_opt(pool_size, RiakOpts, {pool_size, 20}),
%% TODO (Bartek Gorny): improve worker_pool, then use available_worker strategy here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bartekgorny I feel this comment has not aged well. What does it mean? Why would we want to use available_worker?

Opts = lists:append(Opts0),
case wpool:start_sup_pool(make_pool_name(Type, Host, Tag), WpoolOpts) of
%WpoolOpts = maybe_get_wpool_opts_from_callback(Type, WpoolOptsIn, ConnOpts),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, leftovers :)

try
CallbackModule = make_callback_module_name(Type),
CallbackModule:stop(Host, Tag)
catch E:R ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this try/catch dance could be deduplicated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to deduplicate it.

@mongoose-im
Copy link
Collaborator

mongoose-im commented Sep 18, 2018

5603.1 / Erlang 19.3 / small_tests / 55bc875
Reports root / small


5603.2 / Erlang 19.3 / internal_mnesia / 55bc875
Reports root/ big
OK: 1067 / Failed: 0 / User-skipped: 45 / Auto-skipped: 0


5603.3 / Erlang 19.3 / mysql_redis / 55bc875
Reports root/ big
OK: 2832 / Failed: 0 / User-skipped: 222 / Auto-skipped: 0


5603.4 / Erlang 19.3 / odbc_mssql_mnesia / 55bc875
Reports root/ big
OK: 2846 / Failed: 0 / User-skipped: 208 / Auto-skipped: 0


5603.6 / Erlang 19.3 / elasticsearch_and_cassandra_mnesia / 55bc875
Reports root/ big
OK: 445 / Failed: 0 / User-skipped: 8 / Auto-skipped: 0


5603.5 / Erlang 19.3 / ldap_mnesia / 55bc875
Reports root/ big
OK: 1032 / Failed: 0 / User-skipped: 80 / Auto-skipped: 0


5603.8 / Erlang 20.0 / pgsql_mnesia / 55bc875
Reports root/ big / small
OK: 2878 / Failed: 0 / User-skipped: 176 / Auto-skipped: 0


5603.9 / Erlang 21.0 / riak_mnesia / 55bc875
Reports root/ big / small
OK: 1290 / Failed: 0 / User-skipped: 43 / Auto-skipped: 0

@michalwski michalwski closed this Sep 18, 2018
@michalwski michalwski reopened this Sep 18, 2018
@mongoose-im
Copy link
Collaborator

mongoose-im commented Sep 18, 2018

5605.1 / Erlang 19.3 / small_tests / ac51ace
Reports root / small


5605.5 / Erlang 19.3 / ldap_mnesia / ac51ace
Reports root/ big
OK: 1032 / Failed: 0 / User-skipped: 80 / Auto-skipped: 0


5605.3 / Erlang 19.3 / mysql_redis / ac51ace
Reports root/ big
OK: 2832 / Failed: 0 / User-skipped: 222 / Auto-skipped: 0


5605.6 / Erlang 19.3 / elasticsearch_and_cassandra_mnesia / ac51ace
Reports root/ big
OK: 445 / Failed: 0 / User-skipped: 8 / Auto-skipped: 0


5605.2 / Erlang 19.3 / internal_mnesia / ac51ace
Reports root/ big
OK: 1067 / Failed: 0 / User-skipped: 45 / Auto-skipped: 0


5605.4 / Erlang 19.3 / odbc_mssql_mnesia / ac51ace
Reports root/ big
OK: 2846 / Failed: 0 / User-skipped: 208 / Auto-skipped: 0

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #2077 into master will decrease coverage by 1.75%.
The diff coverage is 87.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2077      +/-   ##
==========================================
- Coverage      75%   73.25%   -1.76%     
==========================================
  Files         315      320       +5     
  Lines       28630    28695      +65     
==========================================
- Hits        21474    21020     -454     
- Misses       7156     7675     +519
Impacted Files Coverage Δ
src/cassandra/mongoose_cassandra.erl 66.66% <0%> (-11.12%) ⬇️
src/config/mongoose_config_parser.erl 75.43% <100%> (-0.76%) ⬇️
src/mongoose_wpool_generic.erl 100% <100%> (ø)
src/mod_push_service_mongoosepush.erl 82.35% <100%> (ø) ⬆️
src/ejabberd_app.erl 83.5% <100%> (-2.96%) ⬇️
src/mongoose_redis.erl 94.11% <100%> (-1.34%) ⬇️
src/mongoose_wpool_redis.erl 100% <100%> (ø)
...lobal_distrib/mod_global_distrib_mapping_redis.erl 93.95% <100%> (ø) ⬆️
src/event_pusher/mod_event_pusher_sns.erl 85.52% <100%> (ø) ⬆️
src/event_pusher/mod_event_pusher_push.erl 87.83% <100%> (ø) ⬆️
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db53d0d...0928c80. Read the comment docs.

@mongoose-im
Copy link
Collaborator

mongoose-im commented Sep 19, 2018

5610.1 / Erlang 19.3 / small_tests / 8936dc5
Reports root / small


5610.5 / Erlang 19.3 / ldap_mnesia / 8936dc5
Reports root/ big
OK: 1032 / Failed: 0 / User-skipped: 80 / Auto-skipped: 0


5610.6 / Erlang 19.3 / elasticsearch_and_cassandra_mnesia / 8936dc5
Reports root/ big
OK: 445 / Failed: 0 / User-skipped: 8 / Auto-skipped: 0


5610.3 / Erlang 19.3 / mysql_redis / 8936dc5
Reports root/ big
OK: 2832 / Failed: 0 / User-skipped: 222 / Auto-skipped: 0


5610.2 / Erlang 19.3 / internal_mnesia / 8936dc5
Reports root/ big
OK: 1067 / Failed: 0 / User-skipped: 45 / Auto-skipped: 0


5610.4 / Erlang 19.3 / odbc_mssql_mnesia / 8936dc5
Reports root/ big
OK: 2846 / Failed: 0 / User-skipped: 208 / Auto-skipped: 0


5610.8 / Erlang 20.0 / pgsql_mnesia / 8936dc5
Reports root/ big / small
OK: 2878 / Failed: 0 / User-skipped: 176 / Auto-skipped: 0


5610.9 / Erlang 21.0 / riak_mnesia / 8936dc5
Reports root/ big / small
OK: 1290 / Failed: 0 / User-skipped: 43 / Auto-skipped: 0

@@ -0,0 +1,208 @@
# Outgoing connections

MongooseIM can be configured to talk to external service like databases or HTTP servers in order to get or set required data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MongooseIM can be configured to talk to external service like databases or HTTP servers in order to get or set the required data.

* `cassandra` - pool of connections to cassandra cluster
* `riak` - pool of connections to riak cluster
* `redis` - pool of connections to redis server
* `http` - pool of connections to various HTTP(S) server MongooseIM can talk to, in example HTTP auth backend or HTTP notifications
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http - pool of connections to various HTTP(S) servers MongooseIM can talk to, via an example HTTP auth backend or HTTP notifications ?


All the above pools are managed by [inaka/worker_pool](https://github.com/inaka/worker_pool) library.

Every entry in the `outgoing_pools` is a 5 element tuple like below:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every entry in the outgoing_pools is a 5 element tuple:

* `Tag` is a name to distinguish pools with the same `Type` and `Host` parameter.
* `PoolOptions` is a list of `{key, value}` pairs as defined in [worker_pool doc](https://github.com/inaka/worker_pool#choosing-a-strategy)
with the following exception:
* `strategy` - specifies worker selection strategy for the given pool, default is `best_worker`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strategy - specifies the worker selection strategy for the given pool, default is best_worker,

* `strategy` - specifies worker selection strategy for the given pool, default is `best_worker`,
more details on this can be found in [Choosing strategy in worker_pool doc](https://github.com/inaka/worker_pool#choosing-a-strategy)
* `call_timeout` - specifies the timeout for a call operation to the pool
* `ConnectionOptions` - list options passed to the `start` function of the pool type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConnectionOptions - lists options passed to the start function of the pool type ?

## Riak connection setup

Currently only one Riak connection pool can exist for each supported XMPP host.
It is configured with the following tuple inside `outgoing_pools` config option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is configured with the following tuple inside the outgoing_pools config option.


## Cassandra connection setup

The minimum pool definition for cassandra workers looks like below:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minimum pool definition for cassandra workers looks as follows:

]}.
```

In this case MongooseIM will take by default try to connect to Cassandra server on "localhost" and port 9042.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case MongooseIM will by default try to connect to the Cassandra server on "localhost" and port 9042.
The keyspace used in queries will be mongooseim.


* `Type` is one of the types listed above
* `Host` can be set to:
* `global` - meaning the pool will started once despited the XMPP hosts served by MongooseIM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global - meaning the pool will be started once no matter how many XMPP hosts are served by MongooseIM

@kzemek kzemek merged commit 968f01d into master Sep 19, 2018
@kzemek kzemek deleted the unify-pool-config branch September 19, 2018 12:57
@michalwski michalwski restored the unify-pool-config branch September 19, 2018 14:00
@michalwski michalwski deleted the unify-pool-config branch September 19, 2018 14:01
@fenek fenek added this to the 3.1.0++ milestone Sep 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants