]> source.dussan.org Git - sonarqube.git/commitdiff
fixed ITs - IndexQueue can exhaust connection pool (not actually pool-able)
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 22 Aug 2014 13:39:53 +0000 (15:39 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 22 Aug 2014 13:41:13 +0000 (15:41 +0200)
server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java

index b159aae781a5fe46f3831db953a1e2a77da9bcf7..831772c0822e70017cc800c5398f24550d720191 100644 (file)
@@ -43,10 +43,8 @@ import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingQueue;
 
-public class IndexQueue extends LinkedBlockingQueue<Runnable>
-  implements ServerComponent, WorkQueue<IndexActionRequest> {
+public class IndexQueue implements ServerComponent, WorkQueue<IndexActionRequest> {
 
   protected final Profiling profiling;
 
@@ -55,11 +53,9 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
 
   private static final Logger LOGGER = LoggerFactory.getLogger(IndexQueue.class);
 
-  private static final Integer DEFAULT_QUEUE_SIZE = 200;
-  private static final Integer CONCURRENT_NORMALIZATION_FACTOR = 5;
+  private static final Integer CONCURRENT_NORMALIZATION_FACTOR = 3;
 
   public IndexQueue(Settings settings, SearchClient searchClient, ComponentContainer container) {
-    super(DEFAULT_QUEUE_SIZE);
     this.searchClient = searchClient;
     this.container = container;
     this.profiling = new Profiling(settings);
@@ -94,7 +90,7 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
 
       long refreshTime = this.refreshRequiredIndex(indices);
 
-      LOGGER.debug("-- submitted {} items with {}ms in normalization, {}ms indexing and {}ms refresh({}). Total: {}ms",
+      LOGGER.info("-- submitted {} items with {}ms in normalization, {}ms indexing and {}ms refresh({}). Total: {}ms",
         bulkRequestBuilder.numberOfActions(), normTime, indexTime, refreshTime, indices, (normTime + indexTime + refreshTime));
 
       if (response.hasFailures()) {
@@ -126,9 +122,9 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
 
   private long executeNormalization(BulkRequestBuilder bulkRequestBuilder, List<IndexActionRequest> actions) {
     long normTime = System.currentTimeMillis();
-    ExecutorService executorService = Executors.newFixedThreadPool(CONCURRENT_NORMALIZATION_FACTOR);
-    //invokeAll() blocks until ALL tasks submitted to executor complete
     try {
+      ExecutorService executorService = Executors.newFixedThreadPool(CONCURRENT_NORMALIZATION_FACTOR);
+      //invokeAll() blocks until ALL tasks submitted to executor complete
       for (Future<List<ActionRequest>> updateRequests : executorService.invokeAll(actions)) {
         for (ActionRequest update : updateRequests.get()) {
           if (UpdateRequest.class.isAssignableFrom(update.getClass())) {
@@ -140,10 +136,10 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
           }
         }
       }
+      executorService.shutdown();
     } catch (Exception e) {
       throw new IllegalStateException("Could not execute normalization for stack", e);
     }
-    executorService.shutdown();
     return System.currentTimeMillis() - normTime;
   }