/** * This method scedules the tasks given to the server queues in order to be processed * if there is no tasks so the method will wait until there is something to be processed * NOTE: This method never returns */ public override void sceduleTasks() { Dictionary <String, String> dictionary = new Dictionary <String, String>(); int serverTurn = 0; Url request = null; while (true) { try { // get new request SyncAccessor.getSlot(2, 0); request = SyncAccessor.getFromQueue <Url>(_tasksQueue, _timer); // handle the request if (dictionary.ContainsKey(request.getUrl())) { // if it already exists need to pick another one continue; } else { // if not just mark it as old and continue dictionary.Add(request.getUrl(), null); } // now there's a new request we should put it in the server queues bool needToPutRequest = true; int retryCount = 0; while (needToPutRequest) { SyncAccessor.getSlot(2, 0); if (SyncAccessor.queueSize <Url>(_serversQueues[serverTurn]) < _limit) { needToPutRequest = false; SyncAccessor.getSlot(2, 0); SyncAccessor.putInQueue <Url>(_serversQueues[serverTurn], request); } else { retryCount++; if (retryCount > MAX_RETRY_COUNTER) { serverTurn = (serverTurn + 1) % _serversQueues.Count; } else { Thread.Sleep(_timer * 3); } } } serverTurn = (serverTurn + 1) % _serversQueues.Count; } catch (Exception e) { RuntimeStatistics.addToErrors(1); } } }
private void fillQueue(int minRange, int maxRange) { for (int i = minRange; i < maxRange; i++) { String url = generateString(i); SyncAccessor.putInQueue <Url>(feedback, new Url(url, 0, i % 100, url, i)); } }
public void deployLinksToFrontier(Url urlProcessed) { /* * StreamWriter sw = new StreamWriter("Frontier.txt", true); * string temp = urlProcessed.ToString().Replace("[-]", " " + System.Environment.NewLine); * sw.WriteLine(temp); * sw.Close(); */ SyncAccessor.putInQueue <Url>(queueFronier, urlProcessed); }
/** * This method scedules the tasks given to the server queues in order to be processed * if there is no tasks so the method will wait until there is something to be processed * NOTE: This method never returns */ public override void sceduleTasks() { int serverTurn = 0; bool getNewRequest = true; Url request = null; Url request2 = null; while (true) { try { int inserts = 0; SyncAccessor.getSlot(ThreadsDim + 1, 0); while (SyncAccessor.queueSize <Url>(_tasksQueue) != 0 && inserts < MAX_INSERTS_IN_TIME) { request2 = SyncAccessor.getFromQueue <Url>(_tasksQueue, _timer); _rankingTrie.add(request2); inserts++; } if (getNewRequest) { RuntimeStatistics.setFrontierUrls(_rankingTrie.count()); if (_rankingTrie.count() == 0) { Thread.Sleep(_timer); continue; } request = _rankingTrie.pop(); getNewRequest = false; } SyncAccessor.getSlot(2, 0); if (SyncAccessor.queueSize <Url>(_serversQueues[serverTurn]) < _limit) { SyncAccessor.getSlot(2, 0); SyncAccessor.putInQueue <Url>(_serversQueues[serverTurn], request); getNewRequest = true; } else { getNewRequest = false; } serverTurn = (serverTurn + 1) % _serversQueues.Count; } catch (Exception e) { RuntimeStatistics.addToErrors(1); } } }
/** * This method scedules the tasks given to the server queues in order to be processed * if there is no tasks so the method will wait until there is something to be processed * NOTE: This method never returns */ public void sceduleTasks() { Dictionary <String, String> dictionary = new Dictionary <String, String>(); int serverTurn = 0, iterations = 0; bool getNewRequest = true, needToTerminate = false;; Url request = null; while (needToTerminate == false) { try { if (getNewRequest) { request = SyncAccessor.getFromQueue <Url>(_tasksQueue, _timer); getNewRequest = false; } getNewRequest = true; if (dictionary.ContainsKey(request.getUrl())) { continue; } dictionary.Add(request.getUrl(), null); if (SyncAccessor.queueSize <Url>(_serversQueues[serverTurn]) <= _limit) { SyncAccessor.putInQueue <Url>(_serversQueues[serverTurn], request); } else { getNewRequest = false; } serverTurn = (serverTurn + 1) % _serversQueues.Count; iterations++; if (iterations >= _checkStatusLimit) { iterations = 0; if (_shouldStop) { //System.Console.WriteLine("Frontier Thread recieved should stop"); needToTerminate = true; } } } catch (Exception e) { RuntimeStatistics.addToErrors(1); } } }