mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Database executor parameters were causing performance problems.
This commit is contained in:
@@ -113,8 +113,12 @@ OnClickListener, OnItemClickListener {
|
|||||||
// Wait for the service to be bound and started
|
// Wait for the service to be bound and started
|
||||||
serviceConnection.waitForStartup();
|
serviceConnection.waitForStartup();
|
||||||
// Load the headers from the database
|
// Load the headers from the database
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
Collection<GroupMessageHeader> headers =
|
Collection<GroupMessageHeader> headers =
|
||||||
db.getMessageHeaders(groupId);
|
db.getMessageHeaders(groupId);
|
||||||
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Load took " + duration + " ms");
|
||||||
// Display the headers in the UI
|
// Display the headers in the UI
|
||||||
displayHeaders(headers);
|
displayHeaders(headers);
|
||||||
} catch(NoSuchSubscriptionException e) {
|
} catch(NoSuchSubscriptionException e) {
|
||||||
|
|||||||
@@ -123,7 +123,11 @@ implements OnClickListener, DatabaseListener {
|
|||||||
// We'll also need a contact to receive messages from
|
// We'll also need a contact to receive messages from
|
||||||
ContactId contactId = db.addContact("Dave");
|
ContactId contactId = db.addContact("Dave");
|
||||||
// Finally, we'll need some authors for the messages
|
// Finally, we'll need some authors for the messages
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||||
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Key generation took " + duration + " ms");
|
||||||
byte[] publicKey = keyPair.getPublic().getEncoded();
|
byte[] publicKey = keyPair.getPublic().getEncoded();
|
||||||
PrivateKey privateKey = keyPair.getPrivate();
|
PrivateKey privateKey = keyPair.getPrivate();
|
||||||
Author author = authorFactory.createAuthor("Batman",
|
Author author = authorFactory.createAuthor("Batman",
|
||||||
@@ -150,6 +154,7 @@ implements OnClickListener, DatabaseListener {
|
|||||||
}
|
}
|
||||||
Group g = i % 2 == 0 ? group : group1;
|
Group g = i % 2 == 0 ? group : group1;
|
||||||
Message m;
|
Message m;
|
||||||
|
now = System.currentTimeMillis();
|
||||||
if(i % 5 == 0) {
|
if(i % 5 == 0) {
|
||||||
m = messageFactory.createAnonymousMessage(null, g,
|
m = messageFactory.createAnonymousMessage(null, g,
|
||||||
"text/plain", body.getBytes("UTF-8"));
|
"text/plain", body.getBytes("UTF-8"));
|
||||||
@@ -162,9 +167,20 @@ implements OnClickListener, DatabaseListener {
|
|||||||
g, author1, privateKey, "text/plain",
|
g, author1, privateKey, "text/plain",
|
||||||
body.getBytes("UTF-8"));
|
body.getBytes("UTF-8"));
|
||||||
}
|
}
|
||||||
|
duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Message creation took " +
|
||||||
|
duration + " ms");
|
||||||
|
}
|
||||||
|
now = System.currentTimeMillis();
|
||||||
if(Math.random() < 0.5) db.addLocalGroupMessage(m);
|
if(Math.random() < 0.5) db.addLocalGroupMessage(m);
|
||||||
else db.receiveMessage(contactId, m);
|
else db.receiveMessage(contactId, m);
|
||||||
db.setReadFlag(m.getId(), i % 4 == 0);
|
db.setReadFlag(m.getId(), i % 4 == 0);
|
||||||
|
duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Message storage took " +
|
||||||
|
duration + " ms");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Insert a non-text message
|
// Insert a non-text message
|
||||||
Message m = messageFactory.createAnonymousMessage(null,
|
Message m = messageFactory.createAnonymousMessage(null,
|
||||||
@@ -214,9 +230,13 @@ implements OnClickListener, DatabaseListener {
|
|||||||
// Filter out restricted groups
|
// Filter out restricted groups
|
||||||
if(g.getPublicKey() != null) continue;
|
if(g.getPublicKey() != null) continue;
|
||||||
try {
|
try {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
// Load the headers from the database
|
// Load the headers from the database
|
||||||
Collection<GroupMessageHeader> headers =
|
Collection<GroupMessageHeader> headers =
|
||||||
db.getMessageHeaders(g.getId());
|
db.getMessageHeaders(g.getId());
|
||||||
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Full load took " + duration + " ms");
|
||||||
// Display the headers in the UI
|
// Display the headers in the UI
|
||||||
displayHeaders(g, headers);
|
displayHeaders(g, headers);
|
||||||
} catch(NoSuchSubscriptionException e) {
|
} catch(NoSuchSubscriptionException e) {
|
||||||
@@ -312,7 +332,14 @@ implements OnClickListener, DatabaseListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForStartup();
|
serviceConnection.waitForStartup();
|
||||||
displayHeaders(db.getGroup(g), db.getMessageHeaders(g));
|
long now = System.currentTimeMillis();
|
||||||
|
Group group = db.getGroup(g);
|
||||||
|
Collection<GroupMessageHeader> headers =
|
||||||
|
db.getMessageHeaders(g);
|
||||||
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Partial load took " + duration + " ms");
|
||||||
|
displayHeaders(group, headers);
|
||||||
} catch(NoSuchSubscriptionException e) {
|
} catch(NoSuchSubscriptionException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Subscription removed");
|
if(LOG.isLoggable(INFO)) LOG.info("Subscription removed");
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
|
|||||||
@@ -111,8 +111,12 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
// Wait for the service to be bound and started
|
// Wait for the service to be bound and started
|
||||||
serviceConnection.waitForStartup();
|
serviceConnection.waitForStartup();
|
||||||
// Load the headers from the database
|
// Load the headers from the database
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
Collection<PrivateMessageHeader> headers =
|
Collection<PrivateMessageHeader> headers =
|
||||||
db.getPrivateMessageHeaders(contactId);
|
db.getPrivateMessageHeaders(contactId);
|
||||||
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Load took " + duration + " ms");
|
||||||
// Display the headers in the UI
|
// Display the headers in the UI
|
||||||
displayHeaders(headers);
|
displayHeaders(headers);
|
||||||
} catch(NoSuchContactException e) {
|
} catch(NoSuchContactException e) {
|
||||||
|
|||||||
@@ -173,8 +173,12 @@ implements OnClickListener, DatabaseListener {
|
|||||||
for(Contact c : db.getContacts()) {
|
for(Contact c : db.getContacts()) {
|
||||||
try {
|
try {
|
||||||
// Load the headers from the database
|
// Load the headers from the database
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
Collection<PrivateMessageHeader> headers =
|
Collection<PrivateMessageHeader> headers =
|
||||||
db.getPrivateMessageHeaders(c.getId());
|
db.getPrivateMessageHeaders(c.getId());
|
||||||
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Full load took " + duration + " ms");
|
||||||
// Display the headers in the UI
|
// Display the headers in the UI
|
||||||
displayHeaders(c, headers);
|
displayHeaders(c, headers);
|
||||||
} catch(NoSuchContactException e) {
|
} catch(NoSuchContactException e) {
|
||||||
@@ -281,8 +285,14 @@ implements OnClickListener, DatabaseListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForStartup();
|
serviceConnection.waitForStartup();
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
Contact contact = db.getContact(c);
|
Contact contact = db.getContact(c);
|
||||||
displayHeaders(contact, db.getPrivateMessageHeaders(c));
|
Collection<PrivateMessageHeader> headers =
|
||||||
|
db.getPrivateMessageHeaders(c);
|
||||||
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Partial load took " + duration + " ms");
|
||||||
|
displayHeaders(contact, headers);
|
||||||
} catch(NoSuchContactException e) {
|
} catch(NoSuchContactException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Contact removed");
|
if(LOG.isLoggable(INFO)) LOG.info("Contact removed");
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package net.sf.briar.db;
|
package net.sf.briar.db;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.concurrent.BlockingQueue;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
|
|
||||||
import net.sf.briar.api.clock.Clock;
|
import net.sf.briar.api.clock.Clock;
|
||||||
import net.sf.briar.api.clock.SystemClock;
|
import net.sf.briar.api.clock.SystemClock;
|
||||||
@@ -21,23 +17,11 @@ import com.google.inject.Singleton;
|
|||||||
|
|
||||||
public class DatabaseModule extends AbstractModule {
|
public class DatabaseModule extends AbstractModule {
|
||||||
|
|
||||||
/** The minimum number of database threads to keep in the pool. */
|
|
||||||
private static final int MIN_DB_THREADS = 1;
|
|
||||||
|
|
||||||
/** The maximum number of database threads. */
|
|
||||||
private static final int MAX_DB_THREADS = 10;
|
|
||||||
|
|
||||||
/** The time in milliseconds to keep unused database threads alive. */
|
|
||||||
private static final int DB_KEEPALIVE = 60 * 1000;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(DatabaseCleaner.class).to(DatabaseCleanerImpl.class);
|
bind(DatabaseCleaner.class).to(DatabaseCleanerImpl.class);
|
||||||
// Database tasks may depend on each other, so use an unbounded queue
|
|
||||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
|
||||||
bind(Executor.class).annotatedWith(DatabaseExecutor.class).toInstance(
|
bind(Executor.class).annotatedWith(DatabaseExecutor.class).toInstance(
|
||||||
new ThreadPoolExecutor(MIN_DB_THREADS, MAX_DB_THREADS,
|
Executors.newCachedThreadPool());
|
||||||
DB_KEEPALIVE, MILLISECONDS, queue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
Reference in New Issue
Block a user