added config key to enable cache warming
This commit is contained in:
1 parent
e45736a692
commit
d4fd3900be
7 files changed
+54
-20
No files matched your search
@@ -3,4 +3,13 @@ package bts.config;
|
||||
|
||||
message Spreader{
|
||||
optional uint32 n_failed_iocs = 10 [default=20];
|
||||
//if this is set to true, the spreader internally
|
||||
//generates fake fills to keep the cache (data and
|
||||
//instruction) warm
|
||||
message CacheWarming{
|
||||
optional bool enable_fills = 10 [default=true];
|
||||
optional double fill_period_low = 20 [default=10];
|
||||
optional double fill_period_high = 30 [default=50];
|
||||
}
|
||||
optional CacheWarming cache_warming = 20;
|
||||
}
|
||||
@@ -13,7 +13,6 @@
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
bts::TimeStamp SpreaderOrder::_cache_warm_fill_ts = bts::TimeStamp();
|
||||
/**************************Cons/Dest*******************************/
|
||||
SpreaderOrder::SpreaderOrder()
|
||||
:
|
||||
@@ -34,6 +33,11 @@ _waiting_for_initial_data_state_worker(this),
|
||||
_working_state_worker(this),
|
||||
_waiting_for_cancel_all_state_worker(this),
|
||||
_end_state_worker(this){
|
||||
LOG(OrderMan, Info,"SpreaderOrder:SpreaderOrder key:{} "
|
||||
"cw::enable_fills:{} cw::fill_fire_period:{}",
|
||||
key(),
|
||||
_cw_helper.enable_fills,
|
||||
_cw_helper.fill_fire_period);
|
||||
_transform_to_START();
|
||||
}
|
||||
SpreaderOrder::~SpreaderOrder () {}
|
||||
@@ -107,8 +111,10 @@ void SpreaderOrder::_on_time(const bts::mercury::TimerEvent& t_event){
|
||||
_send_check_termination(false);
|
||||
if (_any_quoter_in_irrecoverable_error())
|
||||
_state_worker->on_quoter_irrecoverable_error();
|
||||
if(ms_diff(_curr_timestamp,_cache_warm_fill_ts) >= 100){
|
||||
_cache_warm_fill_ts = _curr_timestamp;
|
||||
if(_cw_helper.enable_fills &&
|
||||
ms_diff(_curr_timestamp,_cw_helper.last_cache_warm_fill_ts) >=
|
||||
_cw_helper.fill_fire_period){
|
||||
_cw_helper.last_cache_warm_fill_ts = _curr_timestamp;
|
||||
_keep_hedging_path_hot_2();
|
||||
}
|
||||
}
|
||||
@@ -176,7 +182,7 @@ void SpreaderOrder::_on_child_order_update(const OrderStateUpdateEvent& ord_ev){
|
||||
LOG(OrderMan,_cw_helper.llevel,"h_p cb done {} {}",cb_type, _diff_ns());
|
||||
_send_check_termination(true);
|
||||
LOG(OrderMan,_cw_helper.llevel,"h_p ch_term {} {}",cb_type, _diff_ns());
|
||||
_report_state(!_cw_helper.is_forced);
|
||||
_report_state(!_cw_helper.is_warm_state);
|
||||
LOG(OrderMan,_cw_helper.llevel,"h_p rep {} {}",cb_type, _diff_ns());
|
||||
LOG(OrderMan, _cw_helper.llevel,"_on_child_order_update {} {}",
|
||||
cb_type,
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "lib/orderman/events/OrderStateUpdateEvent.h"
|
||||
#include "lib/orderman/events/BookUpdateEvent.h"
|
||||
#include "lib/mercury/events/TimerEvent.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/spreader.pb.h"
|
||||
|
||||
//using namespace bts::orderman;
|
||||
|
||||
@@ -35,37 +37,47 @@ friend class SpreaderWorkingStateWorker;
|
||||
friend class SpreaderWaitingForCancelAllStateWorker;
|
||||
friend class SpreaderEndStateWorker;
|
||||
public:
|
||||
class CacheWarmingHelper{
|
||||
public:
|
||||
bool is_forced;
|
||||
class CacheWarmingState{
|
||||
public:
|
||||
const bool enable_fills;
|
||||
const uint32_t fill_fire_period;
|
||||
bool is_warm_state;
|
||||
char fill_indicator;
|
||||
log::Level llevel;
|
||||
log::Level llevel;
|
||||
Quantity forced_fill_qty;
|
||||
double fill_mult=1;
|
||||
CacheWarmingHelper()
|
||||
bts::TimeStamp last_cache_warm_fill_ts;
|
||||
CacheWarmingState()
|
||||
:
|
||||
is_forced(false),
|
||||
enable_fills(config::get<config::Spreader>().cache_warming().enable_fills()),
|
||||
fill_fire_period(
|
||||
SpreaderUtils::random_number(
|
||||
config::get<config::Spreader>().cache_warming().fill_period_low(),
|
||||
config::get<config::Spreader>().cache_warming().fill_period_high()
|
||||
)),
|
||||
is_warm_state(false),
|
||||
fill_indicator('f'),
|
||||
llevel(Info),
|
||||
forced_fill_qty(Quantity(0)),
|
||||
fill_mult(1)
|
||||
llevel(Info),
|
||||
forced_fill_qty(0),
|
||||
fill_mult(1),
|
||||
last_cache_warm_fill_ts()
|
||||
{}
|
||||
void set_forced_flag(){
|
||||
is_forced=true;
|
||||
is_warm_state=true;
|
||||
fill_indicator='k';
|
||||
llevel = Diag;
|
||||
forced_fill_qty=Quantity(100);
|
||||
fill_mult=0.0;
|
||||
}
|
||||
void unset_forced_flag(){
|
||||
is_forced=false;
|
||||
is_warm_state=false;
|
||||
fill_indicator='f';
|
||||
llevel = Info;
|
||||
forced_fill_qty=Quantity(0);
|
||||
fill_mult=1.0;
|
||||
}
|
||||
Quantity comp_fill_qty(const SpreaderChildOrderState& o) const{
|
||||
//if is_forced == true, o.last_update_filled_quantity()=0
|
||||
//if is_warm_state == true, o.last_update_filled_quantity()=0
|
||||
//so it will return forced_fill_qty;
|
||||
//else forced_fill_qty == 0, it will return last_update_filled_quantity
|
||||
return Quantity(o.last_update_filled_quantity().value() +
|
||||
@@ -101,7 +113,7 @@ private:
|
||||
bool _cancel_hedges_on_cancel;
|
||||
// helps with forced calls, and all the artificiality of these
|
||||
// calls are trapped here
|
||||
CacheWarmingHelper _cw_helper;
|
||||
CacheWarmingState _cw_helper;
|
||||
// timeout before cancel waiting goes to end
|
||||
const int64_t _cancel_timeout;
|
||||
// period on which check termination calls are
|
||||
@@ -114,7 +126,6 @@ private:
|
||||
bts::TimeStamp _curr_timestamp;
|
||||
// spreader fires a periodic check
|
||||
bts::TimeStamp _last_check_termination_timestamp;
|
||||
static bts::TimeStamp _cache_warm_fill_ts;
|
||||
// current state
|
||||
utils::TimeStamp _perf_ts;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "lib/orderman/orders/spreader_orders/spreader/quoter/QuoteLegDriver.h"
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
|
||||
#include <random>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
@@ -815,6 +816,12 @@ public:
|
||||
static uint32_t _round_leg_qty_computed_from_another_leg_qty (double qty){
|
||||
return static_cast<uint32_t>(std::round(qty));
|
||||
}
|
||||
static double random_number(double min, double max){
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
|
||||
std::uniform_real_distribution<> dis(min, max);
|
||||
return dis(gen);
|
||||
}
|
||||
/**********************************************************************/
|
||||
/**************************debugging helpers***************************/
|
||||
/**********************************************************************/
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ _spreader(spreader){
|
||||
SpreaderState SpreaderStartStateWorker::state() const {
|
||||
return SpreaderState::START;
|
||||
}
|
||||
void SpreaderStartStateWorker::on_transition (){
|
||||
void SpreaderStartStateWorker::on_transition (){
|
||||
}
|
||||
void SpreaderStartStateWorker::on_init_new(const api::orderman::OrderDefinition& order_def,
|
||||
const SpreaderPreActivationOrderServices& spreader_pao_services)
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ void SpreaderWorkingStateWorker::on_quoter_order_error(SpreaderLegData& leg_data
|
||||
}
|
||||
void SpreaderWorkingStateWorker::on_quoter_order_fill(SpreaderLegData& leg_data,
|
||||
trace::CorID trace){
|
||||
SpreaderOrder::CacheWarmingHelper& cw=_spreader->_cw_helper;
|
||||
SpreaderOrder::CacheWarmingState& cw=_spreader->_cw_helper;
|
||||
SpreaderChildOrderState& updated_order = leg_data.order_update_message();
|
||||
double mult = cw.fill_mult;
|
||||
LOG(OrderMan, cw.llevel,"h_p w start {} {}",
|
||||
|
||||
@@ -3509,6 +3509,7 @@ TEST_CASE ("memory layout", "[spreader]"){
|
||||
std::cout << "HedgerManager = " << sizeof(HedgerManager) << std::endl;
|
||||
std::cout << "QuoteDriverSetHistory = " << sizeof(QuoteDriverSetHistory) << std::endl;
|
||||
std::cout << "QuoteDriverSet = " << sizeof(QuoteDriverSet) << std::endl;
|
||||
std::cout << "SpreaderOrder::CacheWarmingState = " << sizeof(SpreaderOrder::CacheWarmingState) << std::endl;
|
||||
}
|
||||
TEST_CASE ("4legs_hedging", "[spreader_perf]")
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user