use table generator for better batch insert performances

This commit is contained in:
Athou
2013-06-08 21:56:28 +02:00
3 changed files with 11 additions and 6 deletions

View File

@@ -73,7 +73,7 @@ public class FeedRefreshUpdater {
ApplicationSettings settings = applicationSettingsService.get();
int threads = Math.max(settings.getDatabaseUpdateThreads(), 1);
log.info("Creating database pool with {} threads", threads);
locks = Striped.lazyWeakLock(threads * 1000);
locks = Striped.lazyWeakLock(threads * 100000);
pool = new ThreadPoolExecutor(threads, threads, 0,
TimeUnit.MILLISECONDS,
queue = new ArrayBlockingQueue<Runnable>(500 * threads));
@@ -140,6 +140,8 @@ public class FeedRefreshUpdater {
private boolean updateEntry(final Feed feed, final FeedEntry entry,
final List<FeedSubscription> subscriptions) {
boolean success = false;
String key = StringUtils.trimToEmpty(entry.getGuid() + entry.getUrl());
Lock lock = locks.get(key);
boolean locked = false;
@@ -147,6 +149,7 @@ public class FeedRefreshUpdater {
locked = lock.tryLock(1, TimeUnit.MINUTES);
if (locked) {
feedUpdateService.updateEntry(feed, entry, subscriptions);
success = true;
} else {
log.error("lock timeout for " + feed.getUrl() + " - " + key);
}
@@ -158,7 +161,7 @@ public class FeedRefreshUpdater {
lock.unlock();
}
}
return locked;
return success;
}
private void handlePubSub(final Feed feed) {

View File

@@ -6,13 +6,15 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.TableGenerator;
@SuppressWarnings("serial")
@MappedSuperclass
public abstract class AbstractModel implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "gen")
@TableGenerator(name = "gen", allocationSize = 1000)
private Long id;
public Long getId() {

View File

@@ -18,7 +18,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.model.Feed;
import com.commafeed.backend.services.ApplicationSettingsService;
@@ -33,7 +33,7 @@ public class SubscriptionHandler {
ApplicationSettingsService applicationSettingsService;
@Inject
FeedDAO feedDAO;
FeedRefreshTaskGiver taskGiver;
public void subscribe(Feed feed) {
@@ -81,7 +81,7 @@ public class SubscriptionHandler {
&& StringUtils.contains(message, pushpressError)) {
String[] tokens = message.split(" ");
feed.setPushTopic(tokens[tokens.length - 1]);
feedDAO.saveOrUpdate(feed);
taskGiver.giveBack(feed);
log.debug("handled pushpress subfeed {} : {}", topic,
feed.getPushTopic());
} else {