Skip to content

Commit

Permalink
Drastic performance and memory footprint improvement on ruote engine …
Browse files Browse the repository at this point in the history
…startup when lots of flows are active.

Solves two nasty problems:

    (1) Loading all the expressions from the database just to
        determine if anything needs scheduling (the common case for
        which appears to be "none").  Instead look at all active
        expressions (in DB), determine which classes respond_to
        reschedule, and only load those.

    (2) In doing (1), we drastically reduce the probability of "bloat"
        caused by other threads allocating memory *after* ruote has
        loaded all the expressions but *before* the GC has triggered
        to collect them (since they don't get used in the init
        process).

        These latent, unused objects *do* get destroyed when the GC
        triggers, but because they no longer neighbor the app's heap
        boundary, GC doesn't release the memory back to the system.
  • Loading branch information
jpr5 committed Oct 16, 2009
1 parent f43677e commit 98ec146
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/ruote/dm/storage/dm_storage.rb
Expand Up @@ -114,24 +114,29 @@ def find_expressions (query={})

conditions = {}

# TODO: Update to use DM.repository.adapter.query since there is
# guarantee dm-aggregates is around.
if m = query[:responding_to]
expclass_list = DmExpression.aggregate(:expclass).select do |expclass_name|
::Object.const_get(expclass_name).instance_methods.include?(m.to_s) rescue nil
end
return [] if expclass_list.empty?
conditions[:expclass] = expclass_list
end

if i = query[:wfid]
conditions[:wfid] = i
end
if c = query[:class]
conditions[:expclass] = c.to_s
end

fexps = DataMapper.repository(@dm_repository) {
DataMapper.repository(@dm_repository) {
DmExpression.all(conditions)
}.collect { |e|
e.as_ruote_expression(@context)
}

if m = query[:responding_to]
fexps = fexps.select { |fe| fe.respond_to?(m) }
end

fexps
end

def []= (fei, fexp)
Expand Down Expand Up @@ -162,6 +167,9 @@ def size
DataMapper.repository(@dm_repository) do
#DmExpression.count
# dm-aggregates is in dm-core and dm-core is no ruby 1.9.1 friend

# jpr5: 10/16/09: Actually, dm-aggregates is in dm-more.
# This may have been rectified by now..
DmExpression.all.size
end
end
Expand Down

0 comments on commit 98ec146

Please sign in to comment.