-
Notifications
You must be signed in to change notification settings - Fork 753
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
Set updated tmax value to bidder's MakeRequest implementation #2930
Conversation
tmaxAdjustments will be further used to calculate bidderTmax and decide whether to send request to bidder server
Reducing the amount of time bidders have to compensate for the processing time used by PBS to fetch a stored request (if needed), validate the OpenRTB request and split it into multiple requests sanitized for each bidder. As well as for the time needed by PBS to prepare the auction response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments related to code optimization and better structuring.
Just want to confirm:
-do duration values in type TmaxAdjustments struct
should be validated?
-do duration values in type TmaxAdjustments struct
should be converted to Duration?
-will these values somewhow interact with timeout calculated earlier at the endpoint start?
timeout := deps.cfg.AuctionTimeouts.LimitAuctionTimeout(time.Duration(req.TMax) * time.Millisecond)
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithDeadline(ctx, start.Add(timeout))
defer cancel()
}
endpoints/openrtb2/amp_auction.go
Outdated
@@ -248,6 +248,7 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h | |||
QueryParams: r.URL.Query(), | |||
TCF2Config: tcf2Config, | |||
Activities: activities, | |||
TmaxAdjustments: &deps.cfg.TmaxAdjustments, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In config
TmaxAdjustments TmaxAdjustments `mapstructure:"tmax_adjustments"`
is not a pointer.
Here in the AuctionRequest
TmaxAdjustments is a pointer.
Do you think a little optimization makes sense here? Add this evaluation before assigning it here:
tmax := &deps.cfg.TmaxAdjustments
if !deps.cfg.TmaxAdjustments.Enabled {
tmax = nil
}
....
auctionRequest := &exchange.AuctionRequest{
TmaxAdjustments: tmax,
}
It will simplify further checks from:
if bidRequestOptions.tmaxAdjustments != nil && bidRequestOptions.tmaxAdjustments.Enabled && bidRequestOptions.tmaxAdjustments.BidderResponseDurationMin != 0 {...}
to
if bidRequestOptions.tmaxAdjustments != nil && bidRequestOptions.tmaxAdjustments.BidderResponseDurationMin != 0 {...}
Basically bidRequestOptions.tmaxAdjustments.Enabled
will not be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TmaxAdjustments
is being passed/ planned to passed to various downstream functions and these functions will have access to tmaxAdjustments.Enabled
field.
Also consider a scenario, if in future if following code was changed. Then if downstream function don't have tmaxAdjustments.Enabled
check then behaviour of downstream function might change
tmax := &deps.cfg.TmaxAdjustments
if !deps.cfg.TmaxAdjustments.Enabled {
tmax = nil
}
exchange/bidder.go
Outdated
if tmaxAdjustments.Enabled && | ||
tmaxAdjustments.BidderResponseDurationMin != 0 && | ||
(tmaxAdjustments.BidderNetworkLatencyBuffer != 0 || tmaxAdjustments.PBSResponsePreparationDuration != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code looks like a good candidate to be evaluated once at the server start up. These parameters come with the config and will not change per-request.
For the exchange.AuctionRequest
you may use another, more convenient structure with some pre-processed values from configs.
Another point toward this idea is that you use same exact structure you used for config representation.
These structs should be separated (model-view-presenter design pattern). Look at the Activities
example in exchange.AuctionRequest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code looks like a good candidate to be evaluated once at the server start up. These parameters come with the config and will not change per-request.
0
is default value for BidderResponseDurationMin, .BidderNetworkLatencyBuffer and .PBSResponsePreparationDuration
. So we cannot add them at server startup or validate them to return error if 0.
By checking these values !=0
, we make sure that deadline from context are extracted and reduced only if needed. This saves us with some time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this is not what I mean, I didn't express myself clear. My general proposal here is to preprocess data from deps.cfg.TmaxAdjustments and save it to a new structure that will be passed to the endpoints.
Here is a draft with changes: VeronikaSolovei9#4
Please see my commit on top of your changes: VeronikaSolovei9@9965326
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VeronikaSolovei9 thanks for the draft. For now I will defer to using config.TmaxAdjustments
struct. Lets build out this feature and then we can do this enhancement. Being said that, lets see what other reviewers has feedback on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to defer it? This change is simple and makes sense, it is more optimal than current approach and it's all done in draft so you see how it works already. It's better to do everything right at the beginning (especially simple things like this), rather then do it in the follow up PR that can possibly never happen or will be forgotten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VeronikaSolovei9 fb19f5c makes the changes
@VeronikaSolovei9 for this #2930 (review),
Zero is the default values of TmaxAdjustments fields. Also data type of TmaxAdjustments fields is uint which implies values can't be less than 0 and marshalling of config (pbs.yml) at start up would failed. So no additional validation is needed
these values are duration (amount of time) specified in ms prebid-server/config/config.go Lines 1545 to 1562 in 23fffa1
yes timeout deadline earlier at the endpoint start is used further to get elapsed time for determining remaining duration |
# Conflicts: # exchange/exchange.go
We discussed the validation question offline. It will be possibly added in future PRs due to the team decision that validation is optional here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes, LGTM
Reducing the amount of time bidders have to compensate for the processing time used by PBS to,