Authored by sang
package com.yohomars.search.queue;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.*;
/**
* @author gris.wang
* @since 2018/3/8
**/
@Service
public class RunnableQueueFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(RunnableQueueFactory.class);
private static final int QUEUE_THREADS_SIZE = 20;
private static final int QUEUE_THREADS_SIZE = 5;
private static final int MAX_QUEUE_CAPACITY = 100;
private static Map<String,BlockingQueue<Runnable>> queueMap;
... ...
package com.yohomars.search.job;
import com.yohomars.search.index.service.IYohoIndexService;
import com.yohomars.search.queue.RunnableQueueFactory;
import com.yohomars.search.utils.Index;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.yohomars.search.index.service.IYohoIndexService;
import com.yohomars.search.utils.Index;
/**
* 定时任务
*/
... ... @@ -20,9 +20,6 @@ public class IndexRebuildJob {
@Autowired
private IYohoIndexService yohoIndexService;
@Autowired
private RunnableQueueFactory runnableQueueFactory;
/**
* 定时任务重建索引(每1小时执行一次)
... ... @@ -48,7 +45,7 @@ public class IndexRebuildJob {
*/
@Scheduled(cron = "50 */10 * * * ?")
public void appendIndexJob() {
this.appendIndex(Index.social_user);
//this.appendIndex(Index.social_user);
this.appendIndex(Index.content);
}
... ... @@ -62,12 +59,16 @@ public class IndexRebuildJob {
return;
}
String indexName = index.getIndexName();
runnableQueueFactory.addTask(indexName, new Runnable() {
@Override
public void run() {
yohoIndexService.rebuildIndex(indexName);
}
});
yohoIndexService.rebuildIndex(indexName);
// RunnableQueueFactory.getInstance().addTask(indexName, new Runnable() {
// @Override
// public void run() {
// yohoIndexService.rebuildIndex(indexName);
// }
// });
} catch (Exception e) {
LOGGER.error("rebuildIndex error,cause:", e);
}
... ... @@ -84,12 +85,16 @@ public class IndexRebuildJob {
return;
}
String indexName = index.getIndexName();
runnableQueueFactory.addTask(indexName, new Runnable() {
@Override
public void run() {
yohoIndexService.appendIndex(indexName);
}
});
yohoIndexService.appendIndex(indexName);
// RunnableQueueFactory.getInstance().addTask(indexName, new Runnable() {
// @Override
// public void run() {
// yohoIndexService.appendIndex(indexName);
// }
// });
} catch (Exception e) {
LOGGER.error("buildAppendedIndex error,cause:", e);
}
... ...
package com.yohomars.search.restapi;
import com.yohomars.search.index.service.IYohoIndexService;
import com.yohomars.search.queue.RunnableQueueFactory;
import com.yohomars.search.service.IndexService;
import com.yohomars.search.utils.Index;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -14,8 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import com.yohomars.search.index.service.IYohoIndexService;
import com.yohomars.search.service.IndexService;
import com.yohomars.search.utils.Index;
/**
* 索引管理相关请求
... ... @@ -29,18 +30,19 @@ public class IndexController extends BaseController {
private IYohoIndexService yohoIndexService;
@Autowired
private RunnableQueueFactory runnableQueueFactory;
@Autowired
private IndexService indexService;
private void rebuild(String indexName){
runnableQueueFactory.addTask(indexName, new Runnable() {
@Override
public void run() {
yohoIndexService.rebuildIndex(indexName);
}
});
yohoIndexService.rebuildIndex(indexName);
// RunnableQueueFactory.getInstance().addTask(indexName, new Runnable() {
// @Override
// public void run() {
// yohoIndexService.rebuildIndex(indexName);
// }
// });
}
@RequestMapping(value = "/test")
... ...
... ... @@ -7,7 +7,7 @@ yohomarssearch.index.translog.flush_threshold_ops=10000
#indexRebuild
search.index.batch.limit=1000
search.index.batch.max.thread.size=10
search.index.batch.max.thread.size=5
#search
search.minimum.should.match=30%
... ...
... ... @@ -7,7 +7,7 @@ yohomarssearch.index.translog.flush_threshold_ops=${yohomarssearch.index.translo
#indexRebuild
search.index.batch.limit=1000
search.index.batch.max.thread.size=10
search.index.batch.max.thread.size=5
#search
search.minimum.should.match=30%
... ...