High CPU usage diplaying banner ads, but app is idle

1,051 views
Skip to first unread message

Kenfoo

unread,
Sep 4, 2014, 3:04:40 AM9/4/14
to google-adm...@googlegroups.com
Hi

I notice that once I've called adView.loadAds(), my app starts consuming 30%-80% CPU, even when my app is idle.
This happens when I use Google Play Services 4.1.32 (as I'm trying to support API level 8 still).
Problem is still there even when I upgraded to 5.0.89.

I tried calling adView.pause(), adView.destroy(), but CPU usage is still high.

Anybody knows a workaround or fix? Thanks.



My code:

MyActivity.java
package com.example.kenneth.testapp1;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.FrameLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;


public class MyActivity extends ActionBarActivity {

    private AdView adView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        // Load Ad
        adView = new AdView(this);
        adView.setAdUnitId("ca-xxxxxxxx");
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.loadAd(new AdRequest.Builder().build());

        FrameLayout fl = (FrameLayout)findViewById(R.id.frame);
        fl.addView(adView);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}


activity_my.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MyActivity">

    <TextView
        android:text="@string/hello_world"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="bottom" android:background="@android:color/darker_gray"></FrameLayout>


</LinearLayout>



build.gradle:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.kenneth.testapp1"
        minSdkVersion 9
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.0'
//    compile 'com.google.android.gms:play-services:4.1.32'
    compile 'com.google.android.gms:play-services:5.0.89'
}


Monitored CPU use using
adb shell top -m 10




Amy Quispe (AdMob SDK Team)

unread,
Sep 4, 2014, 8:06:30 PM9/4/14
to google-adm...@googlegroups.com
Hi Kenfoo,

I'll look into this. Thanks for reporting.

Amy Quispe

Amy Quispe (AdMob SDK Team)

unread,
Sep 5, 2014, 3:10:49 PM9/5/14
to google-adm...@googlegroups.com
Hi Kenfoo,

Can you try using pauseTimers() on the webview?

Amy Quispe
Message has been deleted
Message has been deleted

Kenfoo

unread,
Sep 6, 2014, 1:09:27 AM9/6/14
to google-adm...@googlegroups.com
Ok, I managed to do it. There is no positive effect.

If I call webView.pauseTimers() right after calling adView.loadAds(), the ad does not show up, and CPU goes to 0%.

But when I call webView.pauseTimers() after my AdListener.onAdLoaded() is called, ad shows and CPU usage is still high. 

I'm attaching the whole Android Studio project in this post for reference.
TestApp1.tar.bz2

Kenfoo

unread,
Sep 9, 2014, 10:14:56 PM9/9/14
to google-adm...@googlegroups.com
Hi...any updates? Did my code help pinpoint the cause?

Thanks!

Amy Quispe (AdMob SDK Team)

unread,
Oct 1, 2014, 2:46:39 PM10/1/14
to google-adm...@googlegroups.com
Hi Kenfoo,

Just to follow up - we are currently trying to fix this issue on the SDK side.

Amy Quispe

myErTha Studios

unread,
Oct 14, 2014, 8:15:12 PM10/14/14
to google-adm...@googlegroups.com
Hi Amy, just wondering if these has been any updates to this? I never noticed the high CPU utilization till I received a complaint from one of our users. Thanks!

Eric Leichtenschlag

unread,
Oct 14, 2014, 10:00:44 PM10/14/14
to google-adm...@googlegroups.com
There isn't an update yet but the SDK team is looking into it.

Thanks,
Eric

kforner

unread,
Nov 17, 2014, 12:02:19 PM11/17/14
to google-adm...@googlegroups.com
Any ETA on this?

Eric Leichtenschlag

unread,
Nov 17, 2014, 8:46:05 PM11/17/14
to google-adm...@googlegroups.com
Good question - requesting an update....

Eric Leichtenschlag

unread,
Nov 19, 2014, 4:51:15 PM11/19/14
to google-adm...@googlegroups.com
So to be transparent: the scope of this bug has changed to a creative issue with how css animations are working. So it won't need an SDK fix. The engine that's rendering the creatives is going under a bigger overhaul, one that skirts this issue. This overhaul is looking like it won't launch before the holidays, unfortunately, so the ETA I've been told is January.

kforner

unread,
Jan 14, 2015, 7:02:27 PM1/14/15
to google-adm...@googlegroups.com, eleich...@google.com
Any word on the "overhaul" of the engine?

Massimo Di Cosimo

unread,
Mar 1, 2015, 2:12:50 AM3/1/15
to google-adm...@googlegroups.com
Any update on how we can properly handle this?
Thank you.
Max

Eric Leichtenschlag (Mobile Ads SDK Team)

unread,
Mar 1, 2015, 5:26:04 PM3/1/15
to google-adm...@googlegroups.com, eleich...@google.com
The new rendering engine is currently running at low percentage experiments, which makes it hard for you to test. However, there were also some changes made in Google Play services 6.7 that reduce CPU usage if adView.pause() / adView.destroy() are used when the app is paused/destroyed.

Brian Coverstone

unread,
May 20, 2016, 10:09:38 AM5/20/16
to Google Mobile Ads SDK Developers, eleich...@google.com
My observations indicate that changes made over the past year have not reduced the CPU usage.

I've also received a number of complaints from employees that there are an increasing number of sites that load slowly (i.e. they load, pause, then they can be viewed/scrolled).  I have discovered this pause is google loading ads.  When I block these services the sites that employ googleadservices load around 70% faster.

As a test, I took a laptop and opened a browser to a page with an ad from googleadservices and let it set, the CPU ran near 100% on one core and the battery died after two hours.  On that same laptop, I opened a browser to a blank page and the CPU sat around 1% with the battery lasting over eight hours.

As the admin, I have blocked googleadservices using wildcard DNS entries and custom scripts companywide.  I do not want to have to do this, but I am left with no choice.  I now receive complaints that google shopping doesn't work properly.  I may be able to script around that, but in the meantime, this is a serious issue.  I imagine I am not the only one.

Vu Chau (Mobile Ads SDK Team)

unread,
May 23, 2016, 2:35:35 PM5/23/16
to Google Mobile Ads SDK Developers, eleich...@google.com
Hi Brian,

Thanks for getting in touch! However, I must note that your feedback is with regards to web ads, rather than mobile ads that this forum supports.  While the performance of mobile ads has improved over time, if you do run into any performance issues, please let us know. 

For performance concerns related to other ad platforms, please reach out to their respective support forum/alias.

Vu Chau
Mobile Ads SDK Team
Reply all
Reply to author
Forward
0 new messages