![]() |
RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
#include <router.h>
Public Types | |
typedef std::map< std::string, AgentInfo > | Agents |
typedef TimeoutMap< Id, AuctionInfo > | InFlight |
typedef std::function< void(const AgentInfoEntry &info)> | OnAgentFn |
Public Member Functions | |
Router (ServiceBase &parent, const std::string &serviceName="router", double secondsUntilLossAssumed=2.0, bool connectPostAuctionLoop=true) | |
Router (std::shared_ptr< ServiceProxies > services, const std::string &serviceName="router", double secondsUntilLossAssumed=2.0, bool connectPostAuctionLoop=true) | |
double | secondsUntilLossAssumed () const |
void | setSecondsUntilLossAssumed (double newValue) |
std::shared_ptr< Banker > | getBanker () const |
void | setBanker (const std::shared_ptr< Banker > &newBanker) |
void | init () |
void | bindTcp () |
void | bindAgents (std::string agentUri) |
void | bindAugmentors (const std::string &uri) |
void | unsafeDisableMonitor () |
virtual void | start (boost::function< void()> onStop=boost::function< void()>()) |
virtual void | sleepUntilIdle () |
void | issueTimestamp () |
virtual size_t | numNonIdle () const |
virtual void | shutdown () |
template<typename F > | |
void | forAllExchanges (F functor) |
void | connectExchange (ExchangeConnector &exchange) |
void | addExchange (ExchangeConnector *exchange) |
void | addExchange (ExchangeConnector &exchange) |
void | addExchange (std::unique_ptr< ExchangeConnector > &&exchange) |
void | startExchange (const std::string &exchangeType, const Json::Value &exchangeConfig) |
void | startExchange (const Json::Value &exchangeConfig) |
void | injectAuction (std::shared_ptr< Auction > auction, double lossTime=INFINITY) |
std::shared_ptr< Auction > | injectAuction (Auction::HandleAuction onAuctionFinished, std::shared_ptr< BidRequest > request, const std::string &requestStr, const std::string &requestStrFormat, double startTime=0.0, double expiryTime=0.0, double lossTime=INFINITY) |
void | notifyFinishedAuction (const Id &auctionId) |
int | numAuctionsInProgress () const |
int | numAuctionsAwaitingResult () const |
Json::Value | getStats () const |
Json::Value | getAgentInfo (const std::string &agent) const |
Json::Value | getAllAgentInfo () const |
Json::Value | getAccountInfo (const AccountKey &account) const |
void | setGlobalBidProbability (double val) |
void | setBidsErrorRate (double val) |
void | setBudgetErrorRate (double val) |
void | setAcceptAuctionProbability (double val) |
virtual Json::Value | getServiceStatus () const |
virtual void | submitToPostAuctionService (std::shared_ptr< Auction > auction, Id auctionId, const Auction::Response &bid) |
void | updateAllAgents () |
AuctionInfo & | addAuction (std::shared_ptr< Auction > auction, Date timeout) |
void | run () |
void | handleAgentMessage (const std::vector< std::string > &message) |
void | checkDeadAgents () |
void | checkExpiredAuctions () |
void | returnErrorResponse (const std::vector< std::string > &message, const std::string &error) |
void | doShutdown () |
std::shared_ptr< AugmentationInfo > | preprocessAuction (const std::shared_ptr< Auction > &auction) |
void | augmentAuction (const std::shared_ptr< AugmentationInfo > &info) |
void | doStartBidding (const std::vector< std::string > &message) |
void | doStartBidding (const std::shared_ptr< AugmentationInfo > &augInfo) |
void | doSubmitted (std::shared_ptr< Auction > auction) |
void | doBid (const std::vector< std::string > &message) |
void | doPong (int level, const std::vector< std::string > &message) |
void | sendPings () |
void | doStats (const std::vector< std::string > &message) |
void | onNewAuction (std::shared_ptr< Auction > auction) |
void | onAuctionDone (std::shared_ptr< Auction > auction) |
void | doConfig (const std::string &agent, std::shared_ptr< const AgentConfig > config) |
void | unconfigure (const std::string &agent, const AgentConfig &config) |
void | configure (const std::string &agent, AgentConfig &config) |
template<typename... Args> | |
void | sendAgentMessage (const std::string &agent, const std::string &messageType, const Date &date, Args...args) |
void | sendBidResponse (const std::string &agent, const AgentInfo &info, BidStatus status, Date timestamp, const std::string &message, const Id &auctionId, int spotNum=-1, Amount price=Amount(), const Auction *auction=0, const std::string &bidData="", const Json::Value &metadata=Json::Value(), const std::string &augmentationsStr="") |
void | forEachAgent (const OnAgentFn &onAgent) const |
void | forEachAccountAgent (const AccountKey &account, const OnAgentFn &onAgent) const |
AgentInfoEntry | getAgentEntry (const std::string &agent) const |
void | throwException (const std::string &key, const std::string &fmt,...) __attribute__((__noreturn__)) |
template<typename... Args> | |
void | logRouterError (const std::string &function, const std::string &exception, Args...args) |
template<typename... Args> | |
void | logMessage (const std::string &channel, Args...args) |
template<typename... Args> | |
void | logMessageNoTimestamp (const std::string &channel, Args...args) |
void | debugAuction (const Id &auction, const std::string &type, const std::vector< std::string > &args=std::vector< std::string >()) |
void | debugAuctionImpl (const Id &auction, const std::string &type, const std::vector< std::string > &args) |
void | debugSpot (const Id &auction, const Id &spot, const std::string &type, const std::vector< std::string > &args=std::vector< std::string >()) |
void | debugSpotImpl (const Id &auction, const Id &spot, const std::string &type, const std::vector< std::string > &args) |
void | expireDebugInfo () |
void | dumpAuction (const Id &auction) const |
void | dumpSpot (const Id &auction, const Id &spot) const |
Date | getCurrentTime () const |
std::string | getProviderName () const |
Json::Value | getProviderIndicators () const |
Public Attributes | |
boost::function< void(double)> | acceptAuctionProbabilityFn |
std::function< void(std::shared_ptr < Auction >, Id, Auction::Response)> | onSubmittedAuction |
ZmqNamedClientBus | agentEndpoint |
ZmqNamedProxy | postAuctionEndpoint |
Agents | agents |
ML::RingBufferSRMW< std::pair < std::string, std::shared_ptr < const AgentConfig > > > | configBuffer |
ML::RingBufferSRMW < std::shared_ptr < AugmentationInfo > > | startBiddingBuffer |
ML::RingBufferSRMW < std::shared_ptr< Auction > > | submittedBuffer |
ML::RingBufferSWMR < std::shared_ptr< Auction > > | auctionGraveyard |
ML::Wakeup_Fd | wakeupMainLoop |
AugmentationLoop | augmentationLoop |
Blacklist | blacklist |
InFlight | inFlight |
DutyCycleEntry | dutyCycleCurrent |
std::vector< DutyCycleEntry > | dutyCycleHistory |
Lock | lock |
std::shared_ptr< Banker > | banker |
double | secondsUntilLossAssumed_ |
double | globalBidProbability |
double | bidsErrorRate |
double | budgetErrorRate |
bool | connectPostAuctionLoop |
AllAgentInfo * | allAgents |
GcLock | allAgentsGc |
AgentConfigurationListener | configListener |
bool | initialized |
std::vector< std::shared_ptr < ExchangeConnector > > | exchanges |
ZmqNamedPublisher | logger |
bool | doDebug |
ML::Spinlock | debugLock |
TimeoutMap< Id, AuctionDebugInfo > | debugInfo |
uint64_t | numAuctions |
uint64_t | numBids |
uint64_t | numNonEmptyBids |
uint64_t | numAuctionsWithBid |
uint64_t | numNoPotentialBidders |
uint64_t | numNoBidders |
MonitorClient | monitorClient |
Date | slowModeLastAuction |
int | slowModeCount |
MonitorProviderClient | monitorProviderClient |
Protected Types | |
typedef std::recursive_mutex | Lock |
typedef std::unique_lock< Lock > | Guard |
Protected Attributes | |
boost::scoped_ptr< boost::thread > | runThread |
boost::scoped_ptr< boost::thread > | cleanupThread |
int | shutdown_ |
typedef std::map<std::string, AgentInfo> RTBKIT::Router::Agents |
typedef TimeoutMap<Id, AuctionInfo> RTBKIT::Router::InFlight |
AuctionInfo & RTBKIT::Router::addAuction | ( | std::shared_ptr< Auction > | auction, |
Date | timeout | ||
) |
void RTBKIT::Router::addExchange | ( | ExchangeConnector * | exchange | ) | [inline] |
void RTBKIT::Router::addExchange | ( | ExchangeConnector & | exchange | ) | [inline] |
void RTBKIT::Router::addExchange | ( | std::unique_ptr< ExchangeConnector > && | exchange | ) | [inline] |
void RTBKIT::Router::augmentAuction | ( | const std::shared_ptr< AugmentationInfo > & | info | ) |
void RTBKIT::Router::bindAgents | ( | std::string | agentUri | ) |
void RTBKIT::Router::bindAugmentors | ( | const std::string & | uri | ) |
void RTBKIT::Router::bindTcp | ( | ) |
void RTBKIT::Router::configure | ( | const std::string & | agent, |
AgentConfig & | config | ||
) |
void RTBKIT::Router::connectExchange | ( | ExchangeConnector & | exchange | ) | [inline] |
Connect the exchange connector to the router, but do not make the router know about or own the exchange.
Used mostly for testing where we want to control the exchange connector objects independently of the router.
This method should almost never be used, as the given exchange will not participate in validation of bidding agent configuration.
void RTBKIT::Router::doBid | ( | const std::vector< std::string > & | message | ) |
void RTBKIT::Router::doConfig | ( | const std::string & | agent, |
std::shared_ptr< const AgentConfig > | config | ||
) |
void RTBKIT::Router::doPong | ( | int | level, |
const std::vector< std::string > & | message | ||
) |
void RTBKIT::Router::doStartBidding | ( | const std::vector< std::string > & | message | ) |
void RTBKIT::Router::doStartBidding | ( | const std::shared_ptr< AugmentationInfo > & | augInfo | ) |
void RTBKIT::Router::doStats | ( | const std::vector< std::string > & | message | ) |
void RTBKIT::Router::doSubmitted | ( | std::shared_ptr< Auction > | auction | ) |
void RTBKIT::Router::forAllExchanges | ( | F | functor | ) | [inline] |
void RTBKIT::Router::forEachAccountAgent | ( | const AccountKey & | account, |
const OnAgentFn & | onAgent | ||
) | const |
void RTBKIT::Router::forEachAgent | ( | const OnAgentFn & | onAgent | ) | const |
Json::Value RTBKIT::Router::getAccountInfo | ( | const AccountKey & | account | ) | const |
Return information about all agents bidding on the given account.
AgentInfoEntry RTBKIT::Router::getAgentEntry | ( | const std::string & | agent | ) | const |
Json::Value RTBKIT::Router::getAgentInfo | ( | const std::string & | agent | ) | const |
Json::Value RTBKIT::Router::getAllAgentInfo | ( | ) | const |
string RTBKIT::Router::getProviderName | ( | ) | const [virtual] |
MonitorProvider interface
Implements RTBKIT::MonitorProvider.
Json::Value RTBKIT::Router::getServiceStatus | ( | ) | const [virtual] |
Return service status.
Reimplemented from Datacratic::ServiceBase.
Json::Value RTBKIT::Router::getStats | ( | ) | const |
void RTBKIT::Router::init | ( | ) |
void RTBKIT::Router::injectAuction | ( | std::shared_ptr< Auction > | auction, |
double | lossTime = INFINITY |
||
) |
Inject an auction into the router. auction: the auction object lossTime: the time at which, if no win was forthcoming, a loss will be assumed and the message sent. If the time is infinity then no message will be sent; if it is equal to 0.0 then secondsSinceLossAssumed will be added to the current time and that value used.
std::shared_ptr< Auction > RTBKIT::Router::injectAuction | ( | Auction::HandleAuction | onAuctionFinished, |
std::shared_ptr< BidRequest > | request, | ||
const std::string & | requestStr, | ||
const std::string & | requestStrFormat, | ||
double | startTime = 0.0 , |
||
double | expiryTime = 0.0 , |
||
double | lossTime = INFINITY |
||
) |
Inject an auction into the router given its components.
onAuctionFinished: this is the callback that will be called once the auction is finished id: string ID to represent the auction. Must be globally unique for the router. request: JSON string with the bid request startTime: time at which the auction starts; if empty the current time will be used expiryTime: time at which the auction expires; if empty the startTime + 30ms will be used. lossTime: the time at which, if no win was forthcoming, a loss will be assumed and the LOSS message sent. If the time is infinity then no message will be sent; if it is equal to 0.0 then secondsSinceLossAssumed will be added to the current time and that value used.
Returns the created auction object.
Note that no error handling will be done on an invalid request; the auction will be silently dropped and the callback never called.
This function does not deal with timeouts. If you want the auction to time out, you should call notifyTooLate on the returned auction at the desired time, externally.
void RTBKIT::Router::issueTimestamp | ( | ) |
void RTBKIT::Router::logMessage | ( | const std::string & | channel, |
Args... | args | ||
) | [inline] |
void RTBKIT::Router::logMessageNoTimestamp | ( | const std::string & | channel, |
Args... | args | ||
) | [inline] |
void RTBKIT::Router::logRouterError | ( | const std::string & | function, |
const std::string & | exception, | ||
Args... | args | ||
) | [inline] |
void RTBKIT::Router::notifyFinishedAuction | ( | const Id & | auctionId | ) |
Notify the router that the given auction will never receive another message and should be forgotten. This is mostly for simulation so that the router knows when it can shut down.
Normally finishedSpot should be called, not finishedAuction. In particular, this message will NOT remove anything from the finished auction structures, which is where auctions end up after a bid.
There is no penalty for not calling this, apart from potentially having to wait one hour before the simulation decides that it is finished.
If the auction doesn't exist, the message will be silently ignored.
int RTBKIT::Router::numAuctionsAwaitingResult | ( | ) | const |
Return the number of auctions awaiting a win/loss message.
int RTBKIT::Router::numAuctionsInProgress | ( | ) | const |
size_t RTBKIT::Router::numNonIdle | ( | ) | const [virtual] |
void RTBKIT::Router::onAuctionDone | ( | std::shared_ptr< Auction > | auction | ) |
void RTBKIT::Router::onNewAuction | ( | std::shared_ptr< Auction > | auction | ) |
std::shared_ptr< AugmentationInfo > RTBKIT::Router::preprocessAuction | ( | const std::shared_ptr< Auction > & | auction | ) |
void RTBKIT::Router::sendAgentMessage | ( | const std::string & | agent, |
const std::string & | messageType, | ||
const Date & | date, | ||
Args... | args | ||
) | [inline] |
void RTBKIT::Router::sendBidResponse | ( | const std::string & | agent, |
const AgentInfo & | info, | ||
BidStatus | status, | ||
Date | timestamp, | ||
const std::string & | message, | ||
const Id & | auctionId, | ||
int | spotNum = -1 , |
||
Amount | price = Amount() , |
||
const Auction * | auction = 0 , |
||
const std::string & | bidData = "" , |
||
const Json::Value & | metadata = Json::Value() , |
||
const std::string & | augmentationsStr = "" |
||
) |
void RTBKIT::Router::sendPings | ( | ) |
void RTBKIT::Router::setAcceptAuctionProbability | ( | double | val | ) | [inline] |
void RTBKIT::Router::setBidsErrorRate | ( | double | val | ) | [inline] |
void RTBKIT::Router::setBudgetErrorRate | ( | double | val | ) | [inline] |
void RTBKIT::Router::setGlobalBidProbability | ( | double | val | ) | [inline] |
void RTBKIT::Router::sleepUntilIdle | ( | ) | [virtual] |
void RTBKIT::Router::start | ( | boost::function< void()> | onStop = boost::function<void ()>() | ) | [virtual] |
void RTBKIT::Router::startExchange | ( | const std::string & | exchangeType, |
const Json::Value & | exchangeConfig | ||
) |
void RTBKIT::Router::startExchange | ( | const Json::Value & | exchangeConfig | ) |
void RTBKIT::Router::submitToPostAuctionService | ( | std::shared_ptr< Auction > | auction, |
Id | auctionId, | ||
const Auction::Response & | bid | ||
) | [virtual] |
void RTBKIT::Router::throwException | ( | const std::string & | key, |
const std::string & | fmt, | ||
... | |||
) |
void RTBKIT::Router::unconfigure | ( | const std::string & | agent, |
const AgentConfig & | config | ||
) |
void RTBKIT::Router::unsafeDisableMonitor | ( | ) |
boost::function<void (double)> RTBKIT::Router::acceptAuctionProbabilityFn |
GcLock RTBKIT::Router::allAgentsGc [mutable] |
std::vector<std::shared_ptr<ExchangeConnector> > RTBKIT::Router::exchanges |
std::function<void (std::shared_ptr<Auction>, Id, Auction::Response)> RTBKIT::Router::onSubmittedAuction |