forked from Archives/Athou_commafeed
use table generator for better batch insert performances
This commit is contained in:
@@ -73,7 +73,7 @@ public class FeedRefreshUpdater {
|
|||||||
ApplicationSettings settings = applicationSettingsService.get();
|
ApplicationSettings settings = applicationSettingsService.get();
|
||||||
int threads = Math.max(settings.getDatabaseUpdateThreads(), 1);
|
int threads = Math.max(settings.getDatabaseUpdateThreads(), 1);
|
||||||
log.info("Creating database pool with {} threads", threads);
|
log.info("Creating database pool with {} threads", threads);
|
||||||
locks = Striped.lazyWeakLock(threads * 1000);
|
locks = Striped.lazyWeakLock(threads * 100000);
|
||||||
pool = new ThreadPoolExecutor(threads, threads, 0,
|
pool = new ThreadPoolExecutor(threads, threads, 0,
|
||||||
TimeUnit.MILLISECONDS,
|
TimeUnit.MILLISECONDS,
|
||||||
queue = new ArrayBlockingQueue<Runnable>(500 * threads));
|
queue = new ArrayBlockingQueue<Runnable>(500 * threads));
|
||||||
@@ -140,6 +140,8 @@ public class FeedRefreshUpdater {
|
|||||||
|
|
||||||
private boolean updateEntry(final Feed feed, final FeedEntry entry,
|
private boolean updateEntry(final Feed feed, final FeedEntry entry,
|
||||||
final List<FeedSubscription> subscriptions) {
|
final List<FeedSubscription> subscriptions) {
|
||||||
|
boolean success = false;
|
||||||
|
|
||||||
String key = StringUtils.trimToEmpty(entry.getGuid() + entry.getUrl());
|
String key = StringUtils.trimToEmpty(entry.getGuid() + entry.getUrl());
|
||||||
Lock lock = locks.get(key);
|
Lock lock = locks.get(key);
|
||||||
boolean locked = false;
|
boolean locked = false;
|
||||||
@@ -147,6 +149,7 @@ public class FeedRefreshUpdater {
|
|||||||
locked = lock.tryLock(1, TimeUnit.MINUTES);
|
locked = lock.tryLock(1, TimeUnit.MINUTES);
|
||||||
if (locked) {
|
if (locked) {
|
||||||
feedUpdateService.updateEntry(feed, entry, subscriptions);
|
feedUpdateService.updateEntry(feed, entry, subscriptions);
|
||||||
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
log.error("lock timeout for " + feed.getUrl() + " - " + key);
|
log.error("lock timeout for " + feed.getUrl() + " - " + key);
|
||||||
}
|
}
|
||||||
@@ -158,7 +161,7 @@ public class FeedRefreshUpdater {
|
|||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return locked;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePubSub(final Feed feed) {
|
private void handlePubSub(final Feed feed) {
|
||||||
|
|||||||
@@ -6,13 +6,15 @@ import javax.persistence.GeneratedValue;
|
|||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
|
import javax.persistence.TableGenerator;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class AbstractModel implements Serializable {
|
public abstract class AbstractModel implements Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.TABLE, generator = "gen")
|
||||||
|
@TableGenerator(name = "gen", allocationSize = 1000)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.HttpGetter;
|
import com.commafeed.backend.HttpGetter;
|
||||||
import com.commafeed.backend.dao.FeedDAO;
|
import com.commafeed.backend.feeds.FeedRefreshTaskGiver;
|
||||||
import com.commafeed.backend.feeds.FeedUtils;
|
import com.commafeed.backend.feeds.FeedUtils;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||||
@@ -33,7 +33,7 @@ public class SubscriptionHandler {
|
|||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsService applicationSettingsService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedDAO feedDAO;
|
FeedRefreshTaskGiver taskGiver;
|
||||||
|
|
||||||
public void subscribe(Feed feed) {
|
public void subscribe(Feed feed) {
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class SubscriptionHandler {
|
|||||||
&& StringUtils.contains(message, pushpressError)) {
|
&& StringUtils.contains(message, pushpressError)) {
|
||||||
String[] tokens = message.split(" ");
|
String[] tokens = message.split(" ");
|
||||||
feed.setPushTopic(tokens[tokens.length - 1]);
|
feed.setPushTopic(tokens[tokens.length - 1]);
|
||||||
feedDAO.saveOrUpdate(feed);
|
taskGiver.giveBack(feed);
|
||||||
log.debug("handled pushpress subfeed {} : {}", topic,
|
log.debug("handled pushpress subfeed {} : {}", topic,
|
||||||
feed.getPushTopic());
|
feed.getPushTopic());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user