Monthly Archives: November 2015

Chrome is Fast, Firefox is Memory Efficient

Chrome is a little faster but uses a lot more RAM. Firefox is a little slower but uses a lot less RAM.

If you browse with only one or a small number of pages open at a time, Chrome is best.

If you browse with 10 or more pages open at a time, Firefox is best. It uses so much less memory, in some cases it runs faster than Chrome because Chrome will consume all your RAM and start swapping long before Firefox does.

On a test I did today on my Ubuntu 15.10 system, with Chrome 46 running with about 12 pages open, overall system RAM usage was 10 GB (and the 8 GB system was swapping). When I opened the same 12 pages in Firefox 42 and closed all Chrome instances, overall RAM usage dropped to 6.5 GB and the system was no longer swapping, so it was much more responsive overall. That’s a savings of 3.5 GB of RAM with only 12 pages open!

The speed difference between Chrome & Firefox is not much on a modern fast system. If you have an older system the difference is more noticeable.

Of course you always need both because there are certain web sites that work only on one or the other. But which will be your default? After making Chrome my default for the past few weeks I’ve switched back to Firefox.

Cyanogenmod 12.1 Battery Life – Fixed!

Some users of Cyanogenmod 12.1 have noticed poor battery life. Recently I encountered this, learned what was causing it and how to fix it. Posting this may help others.

My phone is a Galaxy Note 2 running Cyanogenmod 12.1 nightly build dated Nov 11 2015, but this problem has been reported across a variety of different phones. The GN2 has a big 3100 mAH battery and still makes it through the day despite this bug, but just barely. With this bug fixed, the battery lasts more than twice as long.

Symptoms

Short battery life, phone is always warm when I pick it up, Android’s battery usage screen shows a lot of CPU time spent in Android OS, and the battery life history details (when you touch the battery % graph) shows the device is almost always awake, even when the screen is off and it should be asleep.

Root Cause

If you Google this you can find a more detailed explanation; here is a summary.

The root cause is not in Cyanogenmod, but in Google Apps. The service called Google Play Services uses another service called SystemUpdateService. The notifies the device when a system update is available. This is used mainly by device manufacturers, not by ROMs like Cyanogenmod. The bug is in the Google Play service. It takes a wake lock before checking SystemUpdateService, and if it encounters an error during that check it never releases the wake lock. Basically, some Google programmer didn’t use a try..finally block to ensure the lock is always released. This surely violates Google’s coding standards, but stuff happens – sometimes bugs sneak past code review.

Solutions

I know of 3 ways to solve this. The first didn’t work well for me, but the latter two did.

One solution is to use Cyanogenmod’s Privacy Guard feature to deny wakelocks Google Play Services. This used to work well, but not any more. The current versions of Google Play Services crash when denied the wake lock, which throws a system modal dialog saying Google Play Services has stopped. This re-appears every 5 seconds or so, making the device completely unusable! Yet another violation of Google’s coding standards – if your app can’t get a resource it wants, handle it! Don’t crash and throw a system modal dialog for something as trivial as this.

Another solution is to turn on SystemUpdateService, so Google Play Services no longer fails when it tries to use it, and because it doesn’t fail, it follows the “happy” code path which releases the wake lock it acquired. You might ask, why isn’t this service running already? ROMs like Cyanogenmod don’t use it and usually turn it off to save RAM and battery. If your phone is rooted, you can enable it with this command:

su -c ‘pm enable com.google.android.gms/.update.SystemUpdateService’

NOTE: You might try enabling SystemUpdateService with an app like Disable Service, but I could not because this service never shows up in the list. The above command works whether or not the service appears in the list.

You’ll need to do this every time you boot your phone. You can use apps like Tasker to do that automatically.

The third solution is to prevent Google Play Services from connecting to SystemUpdateService. Apparently, if it can’t connect, it exits cleanly without leaking the wake lock. Yet if tries to connect but the service isn’t running, it does leak the wake lock. In this solution, you can leave SystemUpdateService disabled, which may save a little RAM and battery. The way I do this is with an app called Disable Service. Run the app, select the System tab, select Google Play services, scroll down the list of services it uses (there are hundreds!) to SystemUpdateService, and uncheck it – it will turn red.

You’ll need to do this every time you boot your phone. I haven’t yet found a way to automate it.

Final Note: Google, fix this @#!$%* bug in the Google Play Service! It’s been known for at least a year!!!

Power Moves the Airplane

Actually it’s thrust that moves the airplane, but power determines how much thrust you can get any any given airspeed.

Thrust is what pushes (or pulls) an airplane. Thrust is related to power by a simple equation. Removing constant factors, Power = Thrust * Speed. An engine with a constant power output – like any piston engine – gives max thrust (thus max acceleration) at low speeds, with less and less thrust (thus diminishing acceleration) as speed increases, until you reach top speed, where thrust = drag and acceleration is zero.

Put differently: if someone says, “My engine produces 250 lbs. of thrust” you really know nothing. Why? No engine produces the same thrust at all speeds, and he hasn’t told you at what speed it produces that thrust. But if he says, “My engine produces 250 horsepower” you know everything you need to know. From this you can compute how much thrust it produces at any speed, so given the airplane’s mass and drag coefficient, you can compute its acceleration, climb rate and top speed. In this sense, power is what moves the airplane – it determines how much thrust you can get at any speed.

Another way to think about this: forces move objects. But force alone doesn’t tell us much. Any object that actually moves in the real world, moves a certain distance in a given amount of time. Force * distance is work, and work over time is power.

Here’s another example why Power is what moves things – not force or work: Suppose someone tells you, “My truck has 500 ft. lbs. of torque”. From this it’s impossible to know how fast it can tow a load up a hill. Towing the load up the hill takes a certain amount of work. You can do that work fast or slow. Power is how quickly you do the work. The little electric motor that rolls the truck’s windows up and down can also tow any load up a hill – given enough time, it can do any amount of work. As Archimedes said, “Give me a lever long enough and I’ll move the world”. If you want to tow a real load up a real hill in the real world, you care how long it takes. Power tells you that. If that truck makes that 500 ft.lbs. at 3,000 RPM, it has 3 times as much power as it does if it makes the same torque at 1,000 RPM. And it can tow the load up the hill 3 times faster. If he told you, “My truck has 500 horsepower”, you compute how fast it can tow the load up the hill. Once you know that, it doesn’t matter how much torque it has or at what RPM it makes the torque. Torque * RPM = Power, and any combination of Torque and RPM that makes that power will do the job.

In short: because the airplane moves an actual distance over an actual time in the real world, power is what moves the airplane.

More precisely, Power = Thrust * Speed * Efficiency. The reason we must include efficiency will become clear later.

First, consider an airplane with a fixed pitch prop. At full throttle standing still it pulls around 2300 RPM – well shy of redline. It must be designed this way because otherwise, it wouldn’t be able to fly fast enough. As the airplane starts moving, the prop blades see reduced angle of attack to the oncoming air, which reduces resistance to motion, it would want to spin faster but couldn’t because it would already be at redline. The pilot would have to gradually pull back the throttle during the takeoff roll and climb to avoid over-revving.

Now 2300 RPM is about 85% of redline, and since Torque * RPM = Power, the engine is making 85% of its rated power. If you have a 160 HP engine then you have about 135 HP during the takeoff roll, with the engine at full throttle pulling 2300 RPM.

Propeller efficiency is a key factor – it determines how much of the power the engine is making, is converted into thrust. The rest of the power is converted into noise and turbulence. A propeller achieves its ideal efficiency only at a certain angle of attack. This amounts to a medium-ish airspeed. At slow speeds, and at fast speeds, the propeller is less efficient. So our airplane in the above example effectively has less than 135 HP because it’s moving slowly and the prop is gaining efficiency as it speeds up. To be clear, the engine is making 135 HP but some of that power is being converted into turbulence and noise instead of thrust, so there is less than 135 HP making thrust.

So theoretically, the speed of maximum thrust is zero. That comes directly from Power = Thrust * Speed. But in reality, the speed of maximum thrust is higher. In reality, as you go down the takeoff roll, both power and thrust are increasing because the prop is gaining efficiency as you gain speed.

Now let’s consider 2 key airspeeds: Vx and Vy. Every pilot knows Vx is the airspeed that gives greatest angle of climb. If you need to clear trees on the takeoff roll, fly at Vx. Vy is the airspeed that gives the greatest rate of climb. If you want to climb to 10,000 feet as quickly as possible, fly at Vy. The difference between Vx and Vy is thrust vs. power. That is, Vx is the speed of maximum excess thrust, and Vy is the speed of maximum excess power. Here, excess means, above the amount needed to sustain level flight. Vx is always slower than Vy.

One way to think about this, is every climb has an angle and a rate of altitude gain. The angle is determined by excess thrust beyond what is needed for level flight. The rate of altitude gain is determined by excess power beyond what is needed for level flight. So, max excess thrust gives the biggest angle and max excess power gives the highest rate.

Recall the drag vs speed curve of an airplane in flight. Induced drag is high at low speeds, low at high speeds. Parasitic drag is the opposite. The speed having least total drag is the point where they are equal. This is usually much slower than you would normally fly. In my 172, it’s about 60 knots. This is also the speed at which you can glide the longest distance: called Vldmax. Now, knowing that Vx is the speed at which you have the most excess thrust, and drag is what saps your thrust, you might expect Vx to equal the speed of minimum drag. It’s close to that, but always slower. Why? Because your engine makes more thrust at lower speeds, and the relationship is linear. As you slow down just a bit from Vldmax, total drag increases less than linearly, while thrust increases linearly. This means thrust increases more than drag, giving you more excess thrust. Drag is increasing exponentially as you slow down (or speed up) from Vldmax, so if you slow down even more, drag will increase more than thrust.

Now consider Vy, the speed where you have the most excess power. This is a little more complex than Vx because it depends on efficiency. First let’s derive the airspeed of minimum power. It is always slower than the airspeed of minimum drag. Let’s start from that speed – Vldmax – and find out why. Suppose it takes power P to fly at Vldmax. How much power would it take to fly just a bit slower? Flying slower, the drag increases a little – but less than linear – so our speed dropped more than our drag increased. Drag = Thrust and Power is Thrust * Speed, and we just saw that speed decreased more than thrust increased, which means their product, power, is smaller. Thus the airspeed requiring minimum power is slower than the airspeed of minimum drag. However, if we keep slowing down, drag will increase rapidly and it will require more power – not less!

Here is where propeller efficiency enters the picture. It’s simple and obvious that if power output is constant, then the speed of maximum excess power is equal to the speed of minimum power required for flight. That would be slower than Vldmax, yet we know Vy is higher than Vldmax! But in reality, power output is not constant because propeller efficiency is not constant. Its efficiency peaks at a higher airspeed than Vldmax. Thus when you’re at Vldmax, you have poor propeller efficiency. If you speed up, your propeller becomes more efficient, and the gain in efficiency is greater than the increased power required to fly at the higher airspeed. The speed of maximum excess power is always somewhat higher than Vldmax.