gunthercox / ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots
https://chatterbot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
14.05k stars 4.44k forks source link

Multithreading support during logic adapter selection #110

Open DarkmatterVale opened 8 years ago

DarkmatterVale commented 8 years ago

To increase the speed of processing, multithreading support is really needed.

In the future, when more logic adapters are added including more advanced ones (such as a developer assistant), https://github.com/gunthercox/ChatterBot/blob/master/chatterbot/adapters/logic/multi_adapter.py#L11 will consume a lot of computing resources. If this is all in one thread, it could cause a slowdown of the program this is very noticeable.

Here is my solution: We enable threading at that stage of the processing. In addition, if that is not enough, individual logic adapters can also implement threading, but that is for another issue

gunthercox commented 8 years ago

It might be a good idea to weight the advantages of threading vs multiprocessing for this task. Most computers nowadays are built with multi-core processors.

A multiprocessor implementation of this example would allow multi_adapter.py to run the processes for several adapters in parallel on separate processors. Of course the adapter would still need to wait for each adapter to finish processing, but running them in parallel would still accomplish this faster even if a few adapters were lagging behind the others.

Also, (I have to verify this) but I believe that threading would be restricted to a single core. I do think threading would be quite useful for tasks in some adapters such as where a bit of background processing could provide an advantage. (For instance, an email IO adapter could use a thread to periodically check for new emails, if there were new ones it would add them to a queue for the next time it was called to retrieve data. This would remove the need to wait for a web request to return with the updated information every time the adapter is used.)