Archive for October, 2007

Battery Life of Lithium Ion Batteries

I had been told a long time ago by an engineer, that it was probably best to go through longer charge cycles with Li-ions. It seems that advice was not really correct, according to Wikipedia, and the Battery University.

Apparently Li-ions should be charged more frequently, although I am certain I have heard reports of people suffering ‘memory’ style patterns in some Li-ion batteries when charging really frequently. Maybe this is just the low number of charge cycles these batteries can actually cope with. I should think charging at around the 10% mark is actually the way to go, but not to drain them too low, as apparently this is bad for them too.

Li-ion lifetimes can be extended by cooling the batteries too!

I remember the advice I got regarding AA batteries when I was using a Psion 5, in those days, gently crushing the battery and / or leaving it on a radiator for a few minutes would generally give you enough lifetime to make a short trip home etc.

Battery specs are a pain still, but hopefully it won’t be too long before that changes.

Calling on the GC after Rubygems

Calling GC.start immediately after requiring rubygems cut the raw string size down to 45%. heh.

Please note (update): Eric has said (see comments) that this is better in the latest build of rubygems, and that is now out (0.9.5). Re-running the test (I have 98 gems installed at present), I still see a 75% drop in raw in-memory string size GC’ing after rubygems has loaded. I suspect this has little to do with rubygems itself, but more the manner in which ruby caches file data as it is loaded. That and the fact that the ruby GC has no reason to run automatically at this stage (It is programmed not to, which is another discussion already covered by _why). Whether or not we should care is a whole other kettle of fish. I may have a look into this in the future, as there are actually good points on several sides, from pre-optimisation, to platform optimisation, to actual speed (sometimes it may not matter), to memory fragmentation. I don’t have an answer, and likely no one does right now, and certainly not for all cases. This is information only, it might help someone.

[source:ruby]
RAW = true

def write_strings_to fn
open(fn, ‘w+’) do |f|
ObjectSpace.each_object do |o|
f.send((RAW ? :print : :puts), o) if o.class == String
end
end
end

file = %w[strings_no_gems.log strings_gems_no_gc.log strings_gems.log]

GC.start
write_strings_to file[ 0 ]

require ‘rubygems’
write_strings_to file[ 1 ]

GC.start
write_strings_to file[ 2 ]

last = File.size file[ 0 ]
file.each do |fn|
cur = File.size(fn).to_f
pcge = cur / last * 100
puts “#%26s: %15d bytes, change: %8d%” % [fn, cur, pcge]
last = cur
end
[/source]

The raw byte sizes fluctuated a small amount, but in general, the percentage values stayed the same.

# out_strs.rb
#       strings_no_gems.log:            1707 bytes, change:      100%
#    strings_gems_no_gc.log:           99578 bytes, change:     5833%
#          strings_gems.log:           45533 bytes, change:       45%

I have around 150 gems installed, and requiring rubygems grows the ruby process by around 5mb on my machine.

Clear out your old gems… It could save you time and ram…

So I was just looking through some of the ObjectSpace of one of my apps, and I decided to have a scan over the String list by hand. I’m kinda glad I did, because after my discovery, my copy of ruby is loading quite a bit faster, regularly. No really.

I had facets installed. I’ve never actually used facets in one of my projects, but I have had a look through it a few times in the past mostly out of curiosity. Since I’ve done a gem update before, to update all the gems on my machine, I actually had two copies installed.

Well, comparatively, I went from 3.2mb of strings, down to 2.6mb in my application load, by uninstalling facets.

The observation here is though, that rubygems loads up quite a bit of information about the documentation and files installed on your system as gems. If you want your ruby load times to remain snappy, start removing old gems that you never use. Always remove facets (if you can)… If you use it, start splitting out what you need, and forget the gem. Yes it’s full of useful stuffs and examples, but it’s also huge.

It’s also worth noting I think, that I was on facets versions:  facets-1.4.5 and facets-1.8.54. I installed facets-2.0 just to have a look, and it’s become a little smaller. Anyway, I’m still having it off my machine for now.

blackle power usage

Anyone else looking at the numbers on blackle and realising that it’s probably using more power running the server than it’s actually saving?

Even at 500w for the server and the IP stack, it’s looking at 4380kw/year.