venediktov / vanilla-rtb

Real Time Bidding (RTB) - Demand Side Platform framework
http://forkbid.com
GNU General Public License v3.0
318 stars 85 forks source link

exchange_handler creates redundant wire response with custom response handler #67

Closed venediktov closed 7 years ago

venediktov commented 7 years ago

https://github.com/venediktov/vanilla-rtb/blob/master/rtb/exchange/exchange_handler.hpp#L129 We have a new feature e.g. when HTTP 204 is needed we have provided with exchange_handler.if_response() handler which should be used and custom response should be sent . The custom response is sent OK however exchange_handler redundantly converts standard response to wire format causing lag in performance.

Proposing change remove line L129 and add it below

if (auction_response && timer.expires_from_now().total_milliseconds() > 0) {
                    if(if_response_handler) {
                       auto custom_reply = if_response_handler(auction_response);
                       if ( custom_reply ) {
                          custom_reply(r);
                       } else {
                          wire_response = parser.create_response(auction_response);
                          r << to_string(*wire_response) << http::server::reply::flush("json");
                       }
                    } else {
                       wire_response = parser.create_response(auction_response);
                       r << to_string(*wire_response) << http::server::reply::flush("json");
                    }
                } else {
                    r << http::server::reply::flush("json");
                }

And looking at it again maybe time to re-factor it as this code is too verbose .

venediktov commented 7 years ago

finally we have a fix!