r51142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51141‎ | r51142 | r51143 >
Date:22:04, 28 May 2009
Author:rainman
Status:deferred
Tags:
Comment:
Add support for multiple initial deployment threads
Modified paths:
  • /branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearcherCache.java (modified) (history)

Diff [purge]

Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearcherCache.java
@@ -12,6 +12,7 @@
1313 import java.util.Comparator;
1414 import java.util.HashSet;
1515 import java.util.Hashtable;
 16+import java.util.List;
1617 import java.util.Set;
1718 import java.util.Map.Entry;
1819
@@ -220,6 +221,10 @@
221222 protected static Set<String> initialWarmup = Collections.synchronizedSet(new HashSet<String>());
222223
223224 protected boolean initialDeploymentRunning = false;
 225+
 226+ /** Number of threads to use for initial deployment */
 227+ protected int initialDeploymentThreads = 1;
 228+
224229 /**
225230 * If there is a cached local searcher of iid
226231 *
@@ -452,19 +457,18 @@
453458 * Initialize all local searcher pools
454459 */
455460 protected class InitialDeploymentThread extends Thread {
456 - public void run(){
457 - try{
458 - initialDeploymentRunning = true;
459 - IndexRegistry registry = IndexRegistry.getInstance();
460 - // get local search indexes, deploy sorted by name
461 - ArrayList<IndexId> mys = new ArrayList<IndexId>();
462 - mys.addAll(GlobalConfiguration.getInstance().getMySearch());
463 - Collections.sort(mys,new Comparator<IndexId>(){
464 - public int compare(IndexId o1, IndexId o2) {
465 - return o1.toString().compareTo(o2.toString());
466 - }
467 - });
468 - for(IndexId iid : mys){
 461+ IndexRegistry registry = null;
 462+
 463+ protected class InitialDeployer extends Thread {
 464+ ArrayList<IndexId> iids = new ArrayList<IndexId>();
 465+
 466+ protected InitialDeployer(List<IndexId> iids){
 467+ this.iids.addAll(iids);
 468+ }
 469+
 470+ public void run(){
 471+ log.info("Starting initial deployer for "+iids);
 472+ for(IndexId iid : iids){
469473 try {
470474 // when searcher is linked into "search" path it's good, initialize it
471475 if(!iid.isLogical() && registry.getCurrentSearch(iid) != null){
@@ -480,6 +484,45 @@
481485 log.warn("I/O error warming index for "+iid+" : "+e.getMessage(),e);
482486 }
483487 }
 488+ }
 489+ }
 490+ public void run(){
 491+ try{
 492+ initialDeploymentRunning = true;
 493+ registry = IndexRegistry.getInstance();
 494+ // get local search indexes, deploy sorted by name
 495+ ArrayList<IndexId> mys = new ArrayList<IndexId>();
 496+ mys.addAll(GlobalConfiguration.getInstance().getMySearch());
 497+ Collections.sort(mys,new Comparator<IndexId>(){
 498+ public int compare(IndexId o1, IndexId o2) {
 499+ return o1.toString().compareTo(o2.toString());
 500+ }
 501+ });
 502+ int threadNum = initialDeploymentThreads;
 503+ ArrayList<InitialDeployer> threads = new ArrayList<InitialDeployer>();
 504+
 505+ // divide mys list into chunks and assign them to different worker threads
 506+ int inc = mys.size() / threadNum + 1;
 507+ int start = 0;
 508+ for(int i=0;i<threadNum;i++){
 509+ threads.add(new InitialDeployer(
 510+ mys.subList(start, Math.min(start+inc, mys.size()))));
 511+ start += inc;
 512+ }
 513+
 514+ // start all threads
 515+ for(InitialDeployer t : threads)
 516+ t.start();
 517+
 518+ // wait for all of the threads to finish
 519+ for(InitialDeployer t : threads)
 520+ try {
 521+ t.join();
 522+ } catch (InterruptedException e) {
 523+ log.error("Thread "+t+" didn't finish properly", e);
 524+ }
 525+
 526+
484527 } finally {
485528 initialDeploymentRunning = false;
486529 }
@@ -560,7 +603,9 @@
561604 }
562605
563606 protected SearcherCache(boolean initialize){
564 - searchPoolSize = Configuration.open().getInt("SearcherPool","size",1);
 607+ Configuration config = Configuration.open();
 608+ searchPoolSize = config.getInt("SearcherPool","size",1);
 609+ initialDeploymentThreads = config.getInt("SearcherPool", "initThreads",1);
565610 if(initialize){
566611 initialDeploymentRunning = true;
567612 new InitialDeploymentThread().start();

Status & tagging log