AB-CE / abce

Agent-based computational Economics, the Python library that makes AB modelling easier
http://abce.readthedocs.io
181 stars 62 forks source link

Increase performance #172

Closed Sirorezka closed 5 years ago

Sirorezka commented 5 years ago

Multithreading performance could be increased:

Don't generate agents if they are not in thread: rewrite: ProcessorGroup.insert_or_append:

       for i_id, ap in enumerate(agent_parameters, maxid):

            agent_name = (agent_arguments['group'],i_id)
            if hash(agent_name) % self.processes == self.batch:
                agent = Agent(i_id, simulation_parameters, ap, **agent_arguments)
                agent._send = agent._send_multiprocessing ## send method is rewriten 
                agent._out = defaultdict(list)
                agent.init(**ChainMap(simulation_parameters, ap))

                assert agent.name not in self.agents, agent.name
                agent._str_name = re.sub('[^0-9a-zA-Z_]', '', str(agent.name))
                names[agent.name] = agent.name
                agent._processes = self.processes
                self.agents[agent.name] = agent
rht commented 5 years ago

@Sirorezka agreed. I have observed this as well. Thanks for finding this out!