void LoadBalancer::new_worker(size_t i) { if (worker_proc[i]) { delete worker_proc[i]; worker_proc[i] = nullptr; } if (isFinished()) return; std::string logfilename = my_config.value("workerlog"); if (logfilename.empty()) { worker_proc[i] = createWorker(nullptr, no_channels, static_cast<unsigned int>(i)); } else { // In logfilename, replace all %d with worker number (i.e. i), // adjusting to fixed width by filling with zeroes. auto len = std::to_string(tot_no_workers).size(); auto wno = std::to_string(i); wno = std::string(len-wno.size(), '0') + wno; while (true) { auto pos = logfilename.find("%d"); if (pos == std::string::npos) break; logfilename.replace(pos, 2, wno); } worker_proc[i] = createWorker(logfilename, no_channels, static_cast<unsigned int>(i)); } if (worker_proc[i]) log() << "Created worker " << i << ", pid: " << worker_proc[i]->pid(); }
void WatcherRunner::start() { // Set worker performance counters to an initial state. Watcher::resetWorkerCounters(0); // Enter the watch loop. do { if (use_worker_ && !watch(Watcher::getWorker())) { if (Watcher::fatesBound()) { // A signal has interrupted the watcher. break; } // The watcher failed, create a worker. createWorker(); } // Loop over every managed extension and check sanity. std::vector<std::string> failing_extensions; for (const auto& extension : Watcher::extensions()) { if (!watch(*extension.second)) { if (!createExtension(extension.first)) { failing_extensions.push_back(extension.first); } } } // If any extension creations failed, stop managing them. for (const auto& failed_extension : failing_extensions) { Watcher::removeExtensionPath(failed_extension); } pauseMilli(getWorkerLimit(INTERVAL) * 1000); } while (!interrupted() && ok()); }
ClientController::ClientController() : mThread(new QThread()) { mWorker = createWorker(); mConnection = createConnection(mWorker); mThread->start(); }
Worker * createSingleWorker(){ Worker * wp = NULL; wp = createWorker(1, NULL); if (wp == NULL){ ntLogging(LOG_FATAL,"createSingleWorker failed"); return NULL; } return wp; }
void ThreadPool::unsafeAddWorkers(std::size_t to_create, PolymorphicWorkerFactory factory, LockPtr lock) { this->num_pseudo_workers += to_create; for (std::size_t i = 0; i < to_create; ++i) workers.insert(createWorker(factory)); if (lock) lock->unlock(); }
//! Starts the workpool, creating _minwkrcnt void start(ushort _minwkrcnt = 0){ Locker<Mutex> lock(mtx); if(state() == Running){ return; } if(state() != Stopped){ doStop(lock, true); } wkrcnt = 0; state(Running); for(ushort i(0); i < _minwkrcnt; ++i){ createWorker(); } }
void CController::init() { if(mDeviceCount > 0) { for(int i=0; i<mDeviceCount; ++i) createWorker(i); if(!mThreadCont.empty()) { SHARED_VECQTHREAD::const_iterator it = mThreadCont.begin(); for(; it != mThreadCont.end(); ++it) it->get()->start(QThread::NormalPriority); } mWorkerCont.at(0)->resume(); } }
void createWorkers(struct config* config) { config->workers = malloc(sizeof(struct worker*)*config->n_workers); int i; for( i = 0; i < config->n_workers; i++) { config->workers[i] = createWorker(config, i); } if(config->n_workers > config->n_connections_total ) { printf("Overridge n_connections_total because < n_workers\n"); config->n_connections_total = config->n_workers; } int total_connections = 0; for(i = 0; i < config->n_workers; i++) { int num_worker_connections = config->n_connections_total/config->n_workers + (i < config->n_connections_total % config->n_workers); printf("num_worker_connections %d\n", num_worker_connections); total_connections += num_worker_connections; config->workers[i]->connections = malloc(sizeof(struct conn*) * num_worker_connections); config->workers[i]->nConnections = num_worker_connections; config->workers[i]->received_warmup_keys = 0; int j; int server=i % config->n_servers; for(j = 0; j < num_worker_connections; j++) { config->workers[i]->connections[j] = createConnection(config->server_ip_address[server], config->server_port[server], config->protocol_mode, config->naggles); } int rc; //Create receive thread rc = pthread_create(&config->workers[i]->thread, NULL, workerFunction, config->workers[i]); if(rc) { printf("Error creating receive thread\n"); } } printf("Created %d connections total\n", total_connections); }//createWorkers()