prebid / Prebid.js

Setup and manage header bidding advertising partners without writing code or confusing line items. Prebid.js is open source and free.
https://docs.prebid.org
Apache License 2.0
1.28k stars 2.05k forks source link

Refreshing ads leads to increasing resource usage and page crashes #1328

Closed sanjaypatelgames84 closed 6 years ago

sanjaypatelgames84 commented 7 years ago

Type of issue

bug

Description

When refreshing ads the previously loaded scripts are not removed and continue to use resources eventually leading to unresponsive pages and crashes. I run a site where users play games and as a result they spend a lot of time on the page. So I refresh ads about every two minutes. After 10-15 minutes we notice that there are dozens of scripts loaded repeatedly from header partners and that the page eventually becomes unresponsive due to resource usage.

Steps to reproduce

Call header partners, refresh ads every X minutes until eventually the page crashes.

Expected results

Could they be loaded in their own iframe so they can be removed from the page and freed by the garbage collector? An example of how to do this would be helpful as the refresh examples given don't illustrate how to accomplish this.

mkendall07 commented 7 years ago

Could you list the bidders you are using? Most should not be loading scripts, and those that do load scripts should only do it once. So it's most likely from scripts added via the creative contents.

sanjaypatelgamess84 commented 7 years ago

It appears to be some sort of callback from the bidders. I see dozens of these....

http://ib.adnxs.com/jpt?callback=pbjs.handleAnCB&callback_uid=51d92b56b9cfe&psa=0&id=12345619&size=300x250&referrer=http%3A%2F%2Fexample.com%2Ffeatures%2Fpage

and

http://myurl.openx.net/w/1.0/arj?ju=http%3A%2F%2Fexample.com%2Ffeatures%2Fpage&jr=http%3A%2F%2Fexample.com%2Ffeatures%2Fpage&ch=UTF-8&res=1920x1200x24&ifr=true&tz=240&tws=1090x909&ee=api_sync_write&ef=bt%2Cdb&be=1&bc=hb_pb&auid=123456789&aus=300x250&callback=window.pbjs.oxARJResponse

and

https://securepubads.g.doubleclick.net/gampad/ads?gdfp_req=1&correlator=1234567890123412&output=json_html&callback=googletag.impl.pubads.callbackProxy2&impl=......

For every refresh I see a set of these being added to the header.

sanjaypatelgamess84 commented 7 years ago

@mkendall07 I noticed that other adapters are using the cacheRequest option in the call to loadScript. Is there a better way we can go about it for appnexus, openx, and dfp? They're loading and executing on every single call/refresh and after 15-20 minutes on the page we find 20-30 of these scripts loaded and using a substantial amount of resources.

mkendall07 commented 7 years ago

@sanjaypatelgames84 Those are demand fetches so they cannot be cached. It's possible to remove them from the DOM, although I'm not sure that's what is causing the issue you are seeing. Can you do some performance testing against the site to help pinpoint? https://developers.google.com/web/tools/chrome-devtools/memory-problems/

sanjaypatelgamess84 commented 7 years ago

@mkendall07 Thanks. I will run some performance testing to see where the resources are being used and report back. However, how would I remove those scripts from the DOM?

sanjaypatelgamess84 commented 7 years ago

Live javascript memory is stable. It does go up at times but it seems garbage collection is working properly and it goes back down to a reasonale size and stays at a reasonable size most of the time.

The memory value continues to increase though. I can see it go up and down. The general trend is up. According to the link provided that means that DOM nodes are being created/added.

I'm not sure where to from here. My page goes from 100mb of memory usage to over 500mb after 10 minutes.

YOzaz commented 6 years ago

+1 to this one. Observing memory increase as well.

mkendall07 commented 6 years ago

I think you'll benefit from using safeFrames. Generally speaking the creatives are heavier than the scripts added by prebid.js. SafeFrame would prevent additional resources leaked out/not cleaned up on a ad refresh.