<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -37,6 +37,11 @@ opts = OptionParser.new do |opts|
   opts.on(&quot;--single-threaded&quot;, &quot;Run all operations in one thread&quot;) do
     options[:single_threaded] = true
   end
+  
+  opts.on(&quot;--threadpool COUNT&quot;, &quot;Number of threads to run all operations in&quot;) do |tps|
+    options[:threadpool_size] = tps
+  end
+  
 end
 
 opts.parse!</diff>
      <filename>bin/nanite-agent</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,9 @@ module Nanite
 
     def register(actor, prefix)
       raise ArgumentError, &quot;#{actor.inspect} is not a Nanite::Actor subclass instance&quot; unless Nanite::Actor === actor
-      Nanite::Log.info(&quot;Registering #{actor.inspect} with prefix #{prefix.inspect}&quot;)
+      log_msg = &quot;[actor] #{actor.class.to_s}&quot;
+      log_msg += &quot;, prefix #{prefix}&quot; if prefix &amp;&amp; !prefix.empty?
+      Nanite::Log.info(log_msg)
       prefix ||= actor.class.default_prefix
       actors[prefix.to_s] = actor
     end</diff>
      <filename>lib/nanite/actor_registry.rb</filename>
    </modified>
    <modified>
      <diff>@@ -54,6 +54,8 @@ module Nanite
     #
     # single_threaded: Run all operations in one thread
     #
+    # threadpool_size: Number of threads to run operations in
+    #
     # Connection options:
     #
     # vhost    : AMQP broker vhost that should be used
@@ -158,7 +160,7 @@ module Nanite
       actors = @options[:actors]
       Dir[&quot;#{actors_dir}/*.rb&quot;].each do |actor|
         next if actors &amp;&amp; !actors.include?(File.basename(actor, &quot;.rb&quot;))
-        Nanite::Log.info(&quot;loading actor: #{actor}&quot;)
+        Nanite::Log.info(&quot;[setup] loading #{actor}&quot;)
         require actor
       end
       init_path = @options[:initrb] || File.join(options[:root], 'init.rb')
@@ -166,25 +168,27 @@ module Nanite
     end
 
     def receive(packet)
+      Nanite::Log.debug(&quot;RECV #{packet.to_s}&quot;)
       case packet
       when Advertise
-        Nanite::Log.debug(&quot;handling Advertise: #{packet.inspect}&quot;)
+        Nanite::Log.info(&quot;RECV #{packet.to_s}&quot;) unless Nanite::Log.level == Logger::DEBUG
         advertise_services
       when Request, Push
-        Nanite::Log.debug(&quot;handling Request: #{packet.inspect}&quot;)
         if @security &amp;&amp; !@security.authorize(packet)
+          Nanite::Log.warn(&quot;RECV NOT AUTHORIZED #{packet.to_s}&quot;)
           if packet.kind_of?(Request)
             r = Result.new(packet.token, packet.reply_to, @deny_token, identity)
             amq.queue(packet.reply_to, :no_declare =&gt; options[:secure]).publish(serializer.dump(r))
           end
         else
+          Nanite::Log.info(&quot;RECV #{packet.to_s([:from, :tags])}&quot;) unless Nanite::Log.level == Logger::DEBUG
           dispatcher.dispatch(packet)
         end
       when Result
-        Nanite::Log.debug(&quot;handling Result: #{packet.inspect}&quot;)
+        Nanite::Log.info(&quot;RECV #{packet.to_s([])}&quot;) unless Nanite::Log.level == Logger::DEBUG
         @mapper_proxy.handle_result(packet)
       when IntermediateMessage
-        Nanite::Log.debug(&quot;handling Intermediate Result: #{packet.inspect}&quot;)
+        Nanite::Log.info(&quot;RECV #{packet.to_s([])}&quot;) unless Nanite::Log.level == Logger::DEBUG
         @mapper_proxy.handle_intermediate_result(packet)
       end
     end
@@ -198,10 +202,9 @@ module Nanite
       amq.queue(identity, :durable =&gt; true).subscribe(:ack =&gt; true) do |info, msg|
         begin
           info.ack
-          packet = serializer.load(msg)
-          receive(packet)
+          receive(serializer.load(msg))
         rescue Exception =&gt; e
-          Nanite::Log.error(&quot;Error handling packet: #{e.message}&quot;)
+          Nanite::Log.error(&quot;RECV #{e.message}&quot;)
         end
       end
     end
@@ -231,13 +234,15 @@ module Nanite
     def un_register
       unless @unregistered
         @unregistered = true
+        Nanite::Log.info(&quot;SEND [un_register]&quot;)
         amq.fanout('registration', :no_declare =&gt; options[:secure]).publish(serializer.dump(UnRegister.new(identity)))
       end
     end
 
     def advertise_services
-      Nanite::Log.debug(&quot;advertise_services: #{registry.services.inspect}&quot;)
-      amq.fanout('registration', :no_declare =&gt; options[:secure]).publish(serializer.dump(Register.new(identity, registry.services, status_proc.call, self.tags)))
+      reg = Register.new(identity, registry.services, status_proc.call, self.tags)
+      Nanite::Log.info(&quot;SEND #{reg.to_s}&quot;)
+      amq.fanout('registration', :no_declare =&gt; options[:secure]).publish(serializer.dump(reg))
     end
 
     def parse_uptime(up)</diff>
      <filename>lib/nanite/agent.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,19 +29,19 @@ module Nanite
       case reg
       when Register
         if @security.authorize_registration(reg)
+          Nanite::Log.info(&quot;RECV #{reg.to_s}&quot;)
           nanites[reg.identity] = { :services =&gt; reg.services, :status =&gt; reg.status, :tags =&gt; reg.tags }
           reaper.timeout(reg.identity, agent_timeout + 1) { nanite_timed_out(reg.identity) }
           callbacks[:register].call(reg.identity, mapper) if callbacks[:register]
-          Nanite::Log.info(&quot;registered: #{reg.identity}, #{nanites[reg.identity].inspect}&quot;)
         else
-          Nanite::Log.warning(&quot;registration of #{reg.inspect} not authorized&quot;)
+          Nanite::Log.warn(&quot;RECV NOT AUTHORIZED #{reg.to_s}&quot;)
         end
       when UnRegister
+        Nanite::Log.info(&quot;RECV #{reg.to_s}&quot;)
         nanites.delete(reg.identity)
         callbacks[:unregister].call(reg.identity, mapper) if callbacks[:unregister]
-        Nanite::Log.info(&quot;un-registering: #{reg.identity}&quot;)
       else
-        Nanite::Log.warning(&quot;Registration received an invalid packet type: #{reg.class}&quot;)
+        Nanite::Log.warn(&quot;RECV [register] Invalid packet type: #{reg.class}&quot;)
       end
     end
 
@@ -60,6 +60,7 @@ module Nanite
       begin
         old_target = request.target
         request.target = target unless target == 'mapper-offline'
+        Nanite::Log.info(&quot;SEND #{request.to_s([:from, :tags, :target])}&quot;)
         amq.queue(target).publish(serializer.dump(request), :persistent =&gt; request.persistent)
       ensure
         request.target = old_target
@@ -76,7 +77,9 @@ module Nanite
           nanite[:status] = ping.status
           reaper.reset_with_autoregister_hack(ping.identity, agent_timeout + 1) { nanite_timed_out(ping.identity) }
         else
-          amq.queue(ping.identity).publish(serializer.dump(Advertise.new))
+          packet = Advertise.new
+          Nanite::Log.info(&quot;SEND #{packet.to_s} to #{ping.identity}&quot;)
+          amq.queue(ping.identity).publish(serializer.dump(packet))
         end
       end
     end
@@ -84,6 +87,9 @@ module Nanite
     # forward request coming from agent
     def handle_request(request)
       if @security.authorize_request(request)
+        Nanite::Log.info(&quot;RECV #{request.to_s([:from, :target, :tags])}&quot;) unless Nanite::Log.level == Logger::DEBUG
+        Nanite::Log.debug(&quot;RECV #{request.to_s}&quot;)
+
         intm_handler = lambda do |result, job|
           result = IntermediateMessage.new(request.token, job.request.from, mapper.identity, nil, result)
           forward_response(result, request.persistent)
@@ -99,12 +105,13 @@ module Nanite
           forward_response(result, request.persistent)
         end
       else
-        Nanite::Log.warning(&quot;request #{request.inspect} not authorized&quot;)
+        Nanite::Log.warn(&quot;RECV NOT AUTHORIZED #{request.to_s}&quot;)
       end
     end
     
     # forward response back to agent that originally made the request
     def forward_response(res, persistent)
+      Nanite::Log.info(&quot;SEND #{res.to_s([:to])}&quot;)
       amq.queue(res.to).publish(serializer.dump(res), :persistent =&gt; persistent)
     end
     
@@ -157,10 +164,10 @@ module Nanite
       handler = lambda do |ping|
         begin
           ping = serializer.load(ping)
-          Nanite::Log.debug(&quot;got heartbeat from #{ping.identity}&quot;) if ping.respond_to?(:identity)
+          Nanite::Log.debug(&quot;RECV #{ping.to_s}&quot;) if ping.respond_to?(:to_s)
           handle_ping(ping)
         rescue Exception =&gt; e
-          Nanite::Log.error(&quot;Error handling heartbeat: #{e.message}&quot;)
+          Nanite::Log.error(&quot;RECV [ping] #{e.message}&quot;)
         end
       end
       hb_fanout = amq.fanout('heartbeat', :durable =&gt; true)
@@ -174,11 +181,9 @@ module Nanite
     def setup_registration_queue
       handler = lambda do |msg|
         begin
-          msg = serializer.load(msg)
-          Nanite::Log.debug(&quot;got registration from #{msg.identity}&quot;)
-          register(msg)
+          register(serializer.load(msg))
         rescue Exception =&gt; e
-          Nanite::Log.error(&quot;Error handling registration: #{e.message}&quot;)
+          Nanite::Log.error(&quot;RECV [register] #{e.message}&quot;)
         end
       end
       reg_fanout = amq.fanout('registration', :durable =&gt; true)
@@ -192,11 +197,9 @@ module Nanite
     def setup_request_queue
       handler = lambda do |msg|
         begin
-          msg = serializer.load(msg)
-          Nanite::Log.debug(&quot;got request from #{msg.from} of type #{msg.type}&quot;)
-          handle_request(msg)
+          handle_request(serializer.load(msg))
         rescue Exception =&gt; e
-          Nanite::Log.error(&quot;Error handling request: #{e.message}&quot;)
+          Nanite::Log.error(&quot;RECV [request] #{e.message}&quot;)
         end
       end
       req_fanout = amq.fanout('request', :durable =&gt; true)
@@ -212,7 +215,7 @@ module Nanite
       when String
         # backwards compatibility, we assume redis if the configuration option
         # was a string
-        Nanite::Log.info(&quot;using redis for state storage&quot;)
+        Nanite::Log.info(&quot;[setup] using redis for state storage&quot;)
         require 'nanite/state'
         @nanites = Nanite::State.new(@state)
       when Hash</diff>
      <filename>lib/nanite/cluster.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,6 +10,7 @@ module Nanite
       @identity = identity
       @options = options
       @evmclass = EM
+      @evmclass.threadpool_size = @options[:threadpool_size].to_i || 20
     end
 
     def dispatch(deliverable)
@@ -31,12 +32,13 @@ module Nanite
       callback = lambda do |r|
         if deliverable.kind_of?(Request)
           r = Result.new(deliverable.token, deliverable.reply_to, r, identity)
+          Nanite::Log.info(&quot;SEND #{r.to_s([])}&quot;)
           amq.queue(deliverable.reply_to, :no_declare =&gt; options[:secure]).publish(serializer.dump(r))
         end
         r # For unit tests
       end
 
-      if @options[:single_threaded]
+      if @options[:single_threaded] || @options[:thread_poolsize] == 1
         @evmclass.next_tick { callback.call(operation.call) }
       else
         @evmclass.defer(operation, callback)</diff>
      <filename>lib/nanite/dispatcher.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,8 +14,6 @@ module Nanite
     end
 
     def process(msg)
-      Nanite::Log.debug(&quot;processing message: #{msg.inspect}&quot;)
-
       if job = jobs[msg.token]
         job.process(msg)
 </diff>
      <filename>lib/nanite/job.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,7 +30,8 @@ module Nanite
       def level=(loglevel)
         init() unless @logger
         loglevel = loglevel.intern if loglevel.is_a?(String)
-        @logger.info(&quot;Setting log level to #{loglevel.to_s.upcase}&quot;)
+        @logger.info(&quot;[setup] setting log level to #{loglevel.to_s.upcase}&quot;)
+        @level = loglevel
         case loglevel
         when :debug
           @logger.level = Logger::DEBUG
@@ -46,7 +47,7 @@ module Nanite
           raise ArgumentError, &quot;Log level must be one of :debug, :info, :warn, :error, or :fatal&quot;
         end
       end
-      
+
       # Passes any other method calls on directly to the underlying Logger object created with init. If
       # this method gets hit before a call to Nanite::Logger.init has been made, it will call 
       # Nanite::Logger.init() with no arguments.</diff>
      <filename>lib/nanite/log.rb</filename>
    </modified>
    <modified>
      <diff>@@ -68,6 +68,7 @@ module Nanite
     #               broker is restarted. Default is false. Can be overriden on a per-message basis using the request and push methods.
     #
     # secure      : use Security features of rabbitmq to restrict nanites to themselves
+    #
     # prefetch    : Sets prefetch (only supported in RabbitMQ &gt;= 1.6)
     #
     # Connection options:
@@ -123,7 +124,7 @@ module Nanite
       @amq = start_amqp(@options)
       @job_warden = JobWarden.new(@serializer)
       setup_cluster
-      Nanite::Log.info('starting mapper')
+      Nanite::Log.info('[setup] starting mapper')
       setup_queues
       start_console if @options[:console] &amp;&amp; !@options[:daemonize]
     end
@@ -267,11 +268,12 @@ module Nanite
     def setup_message_queue
       amq.queue(identity, :exclusive =&gt; true).bind(amq.fanout(identity)).subscribe do |msg|
         begin
-          msg = serializer.load(msg)
-          Nanite::Log.debug(&quot;got result from #{msg.from}: #{msg.results.inspect}&quot;)
+          msg = serializer.load(msg)     
+          Nanite::Log.debug(&quot;RECV #{msg.to_s}&quot;)
+          Nanite::Log.info(&quot;RECV #{msg.to_s([:from])}&quot;) unless Nanite::Log.level == Logger::DEBUG
           job_warden.process(msg)
         rescue Exception =&gt; e
-          Nanite::Log.error(&quot;Error handling result: #{e.message}&quot;)
+          Nanite::Log.error(&quot;RECV [result] #{e.message}&quot;)
         end
       end
     end</diff>
      <filename>lib/nanite/mapper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,6 +37,7 @@ module Nanite
       request.persistent = opts.key?(:persistent) ? opts[:persistent] : options[:persistent]
       pending_requests[request.token] = 
         { :intermediate_handler =&gt; opts[:intermediate_handler], :result_handler =&gt; blk }
+      Nanite::Log.info(&quot;SEND #{request.to_s([:tags, :target])}&quot;)
       amqp.fanout('request', :no_declare =&gt; options[:secure]).publish(serializer.dump(request))
     end    
     </diff>
      <filename>lib/nanite/mapper_proxy.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,58 +2,111 @@ module Nanite
   # Base class for all Nanite packets,
   # knows how to dump itself to JSON
   class Packet
+
+    attr_accessor :size
+
     def initialize
       raise NotImplementedError.new(&quot;#{self.class.name} is an abstract class.&quot;)
     end
+
     def to_json(*a)
-      {
+      js = {
         'json_class'   =&gt; self.class.name,
         'data'         =&gt; instance_variables.inject({}) {|m,ivar| m[ivar.sub(/@/,'')] = instance_variable_get(ivar); m }
       }.to_json(*a)
+      js = js.chop + &quot;,\&quot;size\&quot;:#{js.size}}&quot;
+      js
+    end
+
+    # Log representation
+    def to_s(filter=nil)
+      res = &quot;[#{ self.class.to_s.split('::').last.
+        gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+        gsub(/([a-z\d])([A-Z])/,'\1_\2').
+        downcase }]&quot;
+      res += &quot; (#{size.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, &quot;\\1,&quot;)} bytes)&quot; if size &amp;&amp; !size.to_s.empty?
+      res
+    end
+
+    # Log friendly name for given agent id
+    def id_to_s(id)
+      case id
+        when /^mapper-/ then 'mapper'
+        when /^nanite-(.*)/ then Regexp.last_match(1)
+        else id
+      end
+    end
+
+    # Wrap given string to given maximum number of characters per line
+    def wrap(txt, col=120)
+      txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, &quot;\\1\\3\n&quot;).chomp
     end
+
   end
 
   # packet that means start of a file transfer
   # operation
   class FileStart &lt; Packet
+
     attr_accessor :filename, :token, :dest
-    def initialize(filename, dest, token)
+
+    def initialize(filename, dest, token, size=nil)
       @filename = filename
       @dest = dest
       @token = token
+      @size = size
     end
 
     def self.json_create(o)
       i = o['data']
-      new(i['filename'], i['dest'], i['token'])
+      new(i['filename'], i['dest'], i['token'], o['size'])
+    end
+
+    def to_s
+      wrap(&quot;#{super} &lt;#{token}&gt; #{filename} to #{dest}&quot;)
     end
   end
 
   # packet that means end of a file transfer
   # operation
   class FileEnd &lt; Packet
+
     attr_accessor :token, :meta
-    def initialize(token, meta)
+
+    def initialize(token, meta, size=nil)
       @token = token
       @meta  = meta
+      @size = size
     end
 
     def self.json_create(o)
       i = o['data']
-      new(i['token'], i['meta'])
+      new(i['token'], i['meta'], o['size'])
+    end
+
+    def to_s
+      wrap(&quot;#{super} &lt;#{token}&gt; meta #{meta}&quot;)
     end
   end
 
   # packet that carries data chunks during a file transfer
   class FileChunk &lt; Packet
+
     attr_accessor :chunk, :token
-    def initialize(token, chunk=nil)
+
+    def initialize(token, size=nil, chunk=nil)
       @chunk = chunk
       @token = token
+      @size = size
     end
+
     def self.json_create(o)
       i = o['data']
-      new(i['token'], i['chunk'])
+      new(i['token'], o['size'], i['chunk'])
+    end
+
+    def to_s
+      &quot;#{super} &lt;#{token}&gt;&quot;
     end
   end
 
@@ -71,25 +124,43 @@ module Nanite
   # target   is the target nanite for the request
   # persistent signifies if this request should be saved to persistent storage by the AMQP broker
   class Request &lt; Packet
+
     attr_accessor :from, :payload, :type, :token, :reply_to, :selector, :target, :persistent, :tags
+
     DEFAULT_OPTIONS = {:selector =&gt; :least_loaded}
-    def initialize(type, payload, opts={})
+
+    def initialize(type, payload, size=nil, opts={})
       opts = DEFAULT_OPTIONS.merge(opts)
-      @type             = type
-      @payload          = payload
-      @from             = opts[:from]
-      @token            = opts[:token]
-      @reply_to         = opts[:reply_to]
-      @selector         = opts[:selector]
-      @target           = opts[:target]
-      @persistent       = opts[:persistent]
-      @tags             = opts[:tags] || []
+      @type       = type
+      @payload    = payload
+      @size       = size
+      @from       = opts[:from]
+      @token      = opts[:token]
+      @reply_to   = opts[:reply_to]
+      @selector   = opts[:selector]
+      @target     = opts[:target]
+      @persistent = opts[:persistent]
+      @tags       = opts[:tags] || []
     end
+
     def self.json_create(o)
       i = o['data']
-      new(i['type'], i['payload'], {:from =&gt; i['from'], :token =&gt; i['token'], :reply_to =&gt; i['reply_to'], :selector =&gt; i['selector'],
-      :target =&gt; i['target'], :persistent =&gt; i['persistent'], :tags =&gt; i['tags']})
+      new(i['type'], i['payload'], o['size'], { :from     =&gt; i['from'],     :token      =&gt; i['token'],
+                                                :reply_to =&gt; i['reply_to'], :selector   =&gt; i['selector'],
+                                                :target   =&gt; i['target'],   :persistent =&gt; i['persistent'],
+                                                :tags     =&gt; i['tags'] })
+    end
+
+    def to_s(filter=nil)
+      log_msg = &quot;#{super} &lt;#{token}&gt; #{type}&quot;
+      log_msg += &quot; from #{id_to_s(from)}&quot; if filter.nil? || filter.include?(:from)
+      log_msg += &quot; to #{id_to_s(target)}&quot; if target &amp;&amp; (filter.nil? || filter.include?(:target))
+      log_msg += &quot;, reply_to #{id_to_s(reply_to)}&quot; if reply_to &amp;&amp; (filter.nil? || filter.include?(:reply_to))
+      log_msg += &quot;, tags #{tags.inspect}&quot; if tags &amp;&amp; !tags.empty? &amp;&amp; (filter.nil? || filter.include?(:tags))
+      log_msg += &quot;, payload #{payload.inspect}&quot; if filter.nil? || filter.include?(:payload)
+      wrap(log_msg)
     end
+
   end
 
   # packet that means a work push from mapper
@@ -105,23 +176,38 @@ module Nanite
   # target   is the target nanite for the request
   # persistent signifies if this request should be saved to persistent storage by the AMQP broker
   class Push &lt; Packet
+
     attr_accessor :from, :payload, :type, :token, :selector, :target, :persistent, :tags
+
     DEFAULT_OPTIONS = {:selector =&gt; :least_loaded}
-    def initialize(type, payload, opts={})
+
+    def initialize(type, payload, size=nil, opts={})
       opts = DEFAULT_OPTIONS.merge(opts)
-      @type             = type
-      @payload          = payload
-      @from             = opts[:from]
-      @token            = opts[:token]
-      @selector         = opts[:selector]
-      @target           = opts[:target]
-      @persistent       = opts[:persistent]
-      @tags             = opts[:tags] || []
+      @type       = type
+      @payload    = payload
+      @size       = size
+      @from       = opts[:from]
+      @token      = opts[:token]
+      @selector   = opts[:selector]
+      @target     = opts[:target]
+      @persistent = opts[:persistent]
+      @tags       = opts[:tags] || []
     end
+
     def self.json_create(o)
       i = o['data']
-      new(i['type'], i['payload'], {:from =&gt; i['from'], :token =&gt; i['token'], :selector =&gt; i['selector'],
-      :target =&gt; i['target'], :persistent =&gt; i['persistent'], :tags =&gt; i['tags']})
+      new(i['type'], i['payload'], o['size'], { :from       =&gt; i['from'],       :token  =&gt; i['token'],
+                                                :selector   =&gt; i['selector'],   :target =&gt; i['target'],
+                                                :persistent =&gt; i['persistent'], :tags   =&gt; i['tags'] })
+    end
+
+    def to_s(filter=nil)
+      log_msg = &quot;#{super} &lt;#{token}&gt; #{type}&quot;
+      log_msg += &quot; from #{id_to_s(from)}&quot; if filter.nil? || filter.include?(:from)
+      log_msg += &quot;, target #{id_to_s(target)}&quot; if target &amp;&amp; (filter.nil? || filter.include?(:target))
+      log_msg += &quot;, tags #{tags.inspect}&quot; if tags &amp;&amp; !tags.empty? &amp;&amp; (filter.nil? || filter.include?(:tags))
+      log_msg += &quot;, payload #{payload.inspect}&quot; if filter.nil? || filter.include?(:payload)
+      wrap(log_msg)
     end
   end
 
@@ -132,16 +218,28 @@ module Nanite
   # token    is a generated request id that mapper uses to identify replies
   # to       is identity of the node result should be delivered to
   class Result &lt; Packet
+
     attr_accessor :token, :results, :to, :from
-    def initialize(token, to, results, from)
+
+    def initialize(token, to, results, from, size=nil)
       @token = token
       @to = to
       @from = from
       @results = results
+      @size = size
     end
+
     def self.json_create(o)
       i = o['data']
-      new(i['token'], i['to'], i['results'], i['from'])
+      new(i['token'], i['to'], i['results'], i['from'], o['size'])
+    end
+
+    def to_s(filter=nil)
+      log_msg = &quot;#{super} &lt;#{token}&gt;&quot;
+      log_msg += &quot; from #{id_to_s(from)}&quot; if filter.nil? || filter.include?(:from)
+      log_msg += &quot; to #{id_to_s(to)}&quot; if filter.nil? || filter.include?(:to)
+      log_msg += &quot; results: #{results.inspect}&quot; if filter.nil? || filter.include?(:results)
+      wrap(log_msg)
     end
   end
 
@@ -153,17 +251,25 @@ module Nanite
   # token    is a generated request id that mapper uses to identify replies
   # to       is identity of the node result should be delivered to
   class IntermediateMessage &lt; Packet
+
     attr_accessor :token, :messagekey, :message, :to, :from
-    def initialize(token, to, from, messagekey, message)
-      @token = token
-      @to = to
-      @from = from
+
+    def initialize(token, to, from, messagekey, message, size=nil)
+      @token      = token
+      @to         = to
+      @from       = from
       @messagekey = messagekey
-      @message = message
+      @message    = message
+      @size       = size
     end
+
     def self.json_create(o)
       i = o['data']
-      new(i['token'], i['to'], i['from'], i['messagekey'], i['message'])
+      new(i['token'], i['to'], i['from'], i['messagekey'], i['message'], o['size'])
+    end
+
+    def to_s
+      wrap(&quot;#{super} &lt;#{token}&gt; from #{id_to_s(from)}, key #{messagekey}&quot;)
     end
   end
 
@@ -174,16 +280,27 @@ module Nanite
   # status   is a load of the node by default, but may be any criteria
   #          agent may use to report it's availability, load, etc
   class Register &lt; Packet
+
     attr_accessor :identity, :services, :status, :tags
-    def initialize(identity, services, status, tags)
-      @status = status
-      @tags = tags
+
+    def initialize(identity, services, status, tags, size=nil)
+      @status   = status
+      @tags     = tags
       @identity = identity
       @services = services
+      @size     = size
     end
+
     def self.json_create(o)
       i = o['data']
-      new(i['identity'], i['services'], i['status'], i['tags'])
+      new(i['identity'], i['services'], i['status'], i['tags'], o['size'])
+    end
+
+    def to_s
+      log_msg = &quot;#{super} #{id_to_s(identity)}&quot;
+      log_msg += &quot;, services: #{services.join(', ')}&quot; if services &amp;&amp; !services.empty?
+      log_msg += &quot;, tags: #{tags.join(', ')}&quot; if tags &amp;&amp; !tags.empty?
+      wrap(log_msg)
     end
   end
 
@@ -191,13 +308,21 @@ module Nanite
   #
   # from     is sender identity
   class UnRegister &lt; Packet
+
     attr_accessor :identity
-    def initialize(identity)
+
+    def initialize(identity, size=nil)
       @identity = identity
+      @size = size
     end
+
     def self.json_create(o)
       i = o['data']
-      new(i['identity'])
+      new(i['identity'], o['size'])
+    end
+  
+    def to_s
+      &quot;#{super} #{id_to_s(identity)}&quot;
     end
   end
 
@@ -206,26 +331,40 @@ module Nanite
   # identity is sender's identity
   # status   is sender's status (see Register packet documentation)
   class Ping &lt; Packet
+
     attr_accessor :identity, :status
-    def initialize(identity, status)
-      @status = status
+
+    def initialize(identity, status, size=nil)
+      @status   = status
       @identity = identity
+      @size     = size
     end
+
     def self.json_create(o)
       i = o['data']
-      new(i['identity'], i['status'])
+      new(i['identity'], i['status'], o['size'])
+    end
+
+    def to_s
+      &quot;#{super} #{id_to_s(identity)} status #{status}&quot;
     end
+
   end
 
   # packet that is sent by workers to the mapper
   # when worker initially comes online to advertise
   # it's services
   class Advertise &lt; Packet
-    def initialize
+
+    def initialize(size=nil)
+      @size = size
     end
+    
     def self.json_create(o)
-      new
+      new(o['size'])
     end
+
   end
+ 
 end
 </diff>
      <filename>lib/nanite/packets.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,7 +30,7 @@ module Nanite
     # of these two service tags
     
     def initialize(redis)
-      Nanite::Log.info(&quot;initializing redis state: #{redis}&quot;)
+      Nanite::Log.info(&quot;[setup] initializing redis state: #{redis}&quot;)
       host, port = redis.split(':')
       host ||= '127.0.0.1'
       port ||= '6379'</diff>
      <filename>lib/nanite/state.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 spec = Gem::Specification.new do |s|
   s.name = 'nanite'
-  s.version = '0.4.1.1'
+  s.version = '0.4.1.2'
   s.platform = Gem::Platform::RUBY
   s.has_rdoc = true
   s.extra_rdoc_files = ['README.rdoc', 'LICENSE', 'TODO']</diff>
      <filename>nanite.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -49,14 +49,14 @@ describe Nanite::ActorRegistry do
 
   it &quot;should log info message that actor was registered&quot; do
     importer = WebDocumentImporter.new
-    Nanite::Log.should_receive(:info).with(&quot;Registering #{importer.inspect} with prefix nil&quot;)
+    Nanite::Log.should_receive(:info).with(&quot;[actor] #{importer.class.to_s}&quot;)
     @registry.register(importer, nil)
   end
 
   it &quot;should handle actors registered with a custom prefix&quot; do
     importer = WebDocumentImporter.new
     @registry.register(importer, 'monkey')
-    @registry.actors['monkey'].should == importer
+    @registry.actor_for('monkey').should == importer
   end
   
 end # Nanite::ActorRegistry</diff>
      <filename>spec/actor_registry_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -186,7 +186,12 @@ describe &quot;Agent:&quot; do
       agent.tags.should include(&quot;sample_tag_1&quot;)
       agent.tags.should include(&quot;sample_tag_2&quot;)
     end
-
+    
+    it &quot;for threadpool_size&quot; do
+      agent = Nanite::Agent.start(:threadpool_size =&gt; 5)
+      agent.dispatcher.evmclass.threadpool_size.should == 5
+    end
+    
   end
   
   describe &quot;Security&quot; do</diff>
      <filename>spec/agent_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -225,7 +225,7 @@ describe Nanite::Cluster do
     
     describe &quot;when sending an invalid packet to the registration queue&quot; do
       it &quot;should log a message statement&quot; do
-        Nanite::Log.should_receive(:warning).with(&quot;Registration received an invalid packet type: Nanite::Ping&quot;)
+        Nanite::Log.logger.should_receive(:warn).with(&quot;RECV [register] Invalid packet type: Nanite::Ping&quot;)
         @cluster.register(Nanite::Ping.new(nil, nil))
       end
     end
@@ -338,7 +338,7 @@ describe Nanite::Cluster do
       @reaper = mock(&quot;Reaper&quot;)
       Nanite::Reaper.stub!(:new).and_return(@reaper)
       @cluster = Nanite::Cluster.new(@amq, 32, &quot;the_identity&quot;, @serializer, @mapper)
-      @request = mock(&quot;Request&quot;, :persistent =&gt; true, :target =&gt; nil, :target= =&gt; nil)
+      @request = mock(&quot;Request&quot;, :persistent =&gt; true, :target =&gt; nil, :target= =&gt; nil, :to_s =&gt; nil)
       @target = mock(&quot;Target of Request&quot;)
     end
 
@@ -381,9 +381,10 @@ describe Nanite::Cluster do
       @reaper = mock(&quot;Reaper&quot;)
       Nanite::Reaper.stub!(:new).and_return(@reaper)
       @request_without_target = mock(&quot;Request&quot;, :target =&gt; nil, :token =&gt; &quot;Token&quot;,
-       :reply_to =&gt; &quot;Reply To&quot;, :from =&gt; &quot;From&quot;, :persistent =&gt; true, :identity =&gt; &quot;Identity&quot;)
+       :reply_to =&gt; &quot;Reply To&quot;, :from =&gt; &quot;From&quot;, :persistent =&gt; true, :identity =&gt; &quot;Identity&quot;,
+       :payload =&gt; &quot;Payload&quot;, :to_s =&gt; nil)
       @request_with_target = mock(&quot;Request&quot;, :target =&gt; &quot;Target&quot;, :token =&gt; &quot;Token&quot;,
-       :reply_to =&gt; &quot;Reply To&quot;, :from =&gt; &quot;From&quot;, :persistent =&gt; true)
+       :reply_to =&gt; &quot;Reply To&quot;, :from =&gt; &quot;From&quot;, :persistent =&gt; true, :payload =&gt; &quot;Payload&quot;, :to_s =&gt; nil)
       @mapper_with_target = mock(&quot;Mapper&quot;, :identity =&gt; &quot;id&quot;)
       @mapper_without_target = mock(&quot;Mapper&quot;, :request =&gt; false, :identity =&gt; @request_without_target.identity)
       @cluster_with_target = Nanite::Cluster.new(@amq, 32, &quot;the_identity&quot;, @serializer, @mapper_with_target)</diff>
      <filename>spec/cluster_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -81,11 +81,6 @@ describe Nanite::JobWarden do
       Nanite::Log.stub!(:debug)
     end
 
-    it &quot;should log debug message about message to be processed&quot; do
-      Nanite::Log.should_receive(:debug)
-      @warden.process(@message)
-    end
-
     it &quot;should hand over processing to job&quot; do
       Nanite::Job.stub!(:new).and_return(@job)
       @job.should_receive(:process).with(@message)</diff>
      <filename>spec/job_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -63,7 +63,7 @@ describe Nanite::Mapper do
       @mapper = Nanite::Mapper.new({:callbacks =&gt; {:register =&gt; lambda {|*args|}}})
       @mapper.stub!(:setup_queues)
       @mapper.stub!(:start_amqp)
-      Nanite::Cluster.should_receive(:new).with(nil, 15, instance_of(String), instance_of(Nanite::Serializer), @mapper, nil, :register =&gt; instance_of(Proc))
+      Nanite::Cluster.should_receive(:new)
       run_in_em {@mapper.run}
     end
   end</diff>
      <filename>spec/mapper_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,10 @@ require 'spec'
 require 'nanite'
 
 module SpecHelpers
-  
+
+  # Initialize logger so it writes to file instead of STDOUT
+  Nanite::Log.init('test', File.join(File.dirname(__FILE__)))
+
   # Create test certificate
   def issue_cert
     test_dn = { 'C'  =&gt; 'US',</diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>75729d53250470386c5679ee329e5e58bc335113</id>
    </parent>
    <parent>
      <id>491ae82bc1a18c2c0e44ab6d4667ee00ab7c5799</id>
    </parent>
  </parents>
  <author>
    <name>Chris Gaffney</name>
    <email>cgaffney@crayoninterface.com</email>
  </author>
  <url>http://github.com/ezmobius/nanite/commit/4074f9c70007bedc4ab9ee617b325861ca39e8a9</url>
  <id>4074f9c70007bedc4ab9ee617b325861ca39e8a9</id>
  <committed-date>2009-08-08T09:55:49-07:00</committed-date>
  <authored-date>2009-08-08T09:55:49-07:00</authored-date>
  <message>Merge commit 'ezmobius/master'</message>
  <tree>3b730a5d868261dbeceba96bda201b1423fec2f9</tree>
  <committer>
    <name>Chris Gaffney</name>
    <email>cgaffney@crayoninterface.com</email>
  </committer>
</commit>
