So i'm have an app with Socket.IO which purpose is to search some data on different sites. Something like crawler... The main problem is that the search process is too long and while it happens my app stucks... For example if one user starts to search second need to wait until first completed...
Each site which need to be searched is represented as a separate class so i do something like:
selected_sites.forEach(function(site_name) {
var site = new sites[site_name];
site.on('found', function(data) {
socket.emit('found', data);
});
site.on('not_found', function() {
socket.emit('not_found', 'Nothing found at ' + site.getSiteName());
});
site.search(socket_data.params);
});
Is it possible somehow to move the "class body | search progress" "somewhere else | in a new thread" so that event loop not be blocked while search in progress?
site.search()implemented? I find it hard to believe that it would be scraping a site synchronously.clusterpackage to run node process on each processor Core, or move complex functions to external node app and do async calls to it from the main app.searchmethod are few requests in which callback are other requests and so on until it reaches the item...site.searchis probably asynchronous. What happens if you putconsole.log(site_name)before callingsite.search?It'll probably output all 11 site names before even start crawling the first item.request, like 500-600 for each site. In general here is this situation zef.me/blog/4561/node-js-and-the-case-of-the-blocked-event-loop