diff options
| author | Alvaro Videla <videlalvaro@gmail.com> | 2015-05-05 18:02:32 +0200 |
|---|---|---|
| committer | Alvaro Videla <videlalvaro@gmail.com> | 2015-05-05 18:02:32 +0200 |
| commit | b9c2c44f9a87d0da42fd2a03b6935dfebaddeaef (patch) | |
| tree | 00303958062d1cbc0901730f2cbe09384ef1443a | |
| parent | a1afa24303378b785f69856796611f056ce726b0 (diff) | |
| download | rabbitmq-server-git-b9c2c44f9a87d0da42fd2a03b6935dfebaddeaef.tar.gz | |
Allows credit flow Credits to be set via configuration
Fixes rabbitmq/rabbitmq-server#143
| -rw-r--r-- | ebin/rabbit_app.in | 4 | ||||
| -rw-r--r-- | src/credit_flow.erl | 15 | ||||
| -rw-r--r-- | test/src/credit_flow_test.erl | 51 | ||||
| -rw-r--r-- | test/src/rabbit_tests.erl | 1 |
4 files changed, 69 insertions, 2 deletions
diff --git a/ebin/rabbit_app.in b/ebin/rabbit_app.in index 654c52bdd3..91eb5847d8 100644 --- a/ebin/rabbit_app.in +++ b/ebin/rabbit_app.in @@ -81,5 +81,7 @@ gen_fsm, ssl]}, {ssl_apps, [asn1, crypto, public_key, ssl]}, %% see rabbitmq-server#114 - {mirroring_flow_control, true} + {mirroring_flow_control, true}, + {credit_flow_initial_credit, 200}, + {credit_flow_more_credit_after, 50} ]}]}. diff --git a/src/credit_flow.erl b/src/credit_flow.erl index fc233b87c3..f8e991ede8 100644 --- a/src/credit_flow.erl +++ b/src/credit_flow.erl @@ -28,7 +28,20 @@ %% is itself blocked - thus the only processes that need to check %% blocked/0 are ones that read from network sockets. --define(DEFAULT_CREDIT, {200, 50}). +-define(DEFAULT_INITIAL_CREDIT, 200). +-define(DEFAULT_MORE_CREDIT_AFTER, 50). + +-define(DEFAULT_CREDIT, + case get(credit_flow_default_credit) of + undefined -> + Val = {rabbit_misc:get_env(rabbit, credit_flow_initial_credit, + ?DEFAULT_INITIAL_CREDIT), + rabbit_misc:get_env(rabbit, credit_flow_more_credit_after, + ?DEFAULT_MORE_CREDIT_AFTER)}, + put(credit_flow_default_credit, Val), + Val; + Val -> Val + end). -export([send/1, send/2, ack/1, ack/2, handle_bump_msg/1, blocked/0, state/0]). -export([peer_down/1]). diff --git a/test/src/credit_flow_test.erl b/test/src/credit_flow_test.erl new file mode 100644 index 0000000000..8ef73e0bad --- /dev/null +++ b/test/src/credit_flow_test.erl @@ -0,0 +1,51 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2011-2014 GoPivotal, Inc. All rights reserved. +%% + +-module(credit_flow_test). + +-export([test_credit_flow_settings/0]). + +test_credit_flow_settings() -> + %% default values + passed = test_proc(200, 50), + + application:set_env(rabbit, credit_flow_initial_credit, 100), + application:set_env(rabbit, credit_flow_more_credit_after, 20), + passed = test_proc(100, 20), + + application:unset_env(rabbit, credit_flow_initial_credit), + application:unset_env(rabbit, credit_flow_more_credit_after), + % back to defaults + passed = test_proc(200, 50), + passed. + +test_proc(InitialCredit, MoreCreditAfter) -> + Pid = spawn(fun dummy/0), + Pid ! {credit, self()}, + {InitialCredit, MoreCreditAfter} = + receive + {credit, Val} -> Val + end, + passed. + +dummy() -> + credit_flow:send(self()), + receive + {credit, From} -> + From ! {credit, get(credit_flow_default_credit)}; + _ -> + dummy() + end. diff --git a/test/src/rabbit_tests.erl b/test/src/rabbit_tests.erl index ab565d1988..3cad6e5938 100644 --- a/test/src/rabbit_tests.erl +++ b/test/src/rabbit_tests.erl @@ -87,6 +87,7 @@ all_tests0() -> end), passed = test_configurable_server_properties(), passed = vm_memory_monitor_tests:all_tests(), + passed = credit_flow_test:test_credit_flow_settings(), passed. do_if_secondary_node(Up, Down) -> |
