Permalink
Browse files

-Rename mail processing job to something more appropriate and impleme…

…nt toString() method

-Add configurable option for performance (actually time to finish jobs) logging
-Add configuration to log4j file to write performance logs in different file
  • Loading branch information...
gousiosg committed Dec 13, 2010
1 parent 0652cce commit 88a6fcc6d15aac911aba710ea8a30e2a9a166443
@@ -62,15 +62,17 @@
public LogManagerImpl() {}
public Logger createLogger(String name) {
LoggerImpl logger = null;
LoggerImpl logger = loggers.get(name);
org.apache.log4j.Logger.getRootLogger().info(
if (logger == null) {
org.apache.log4j.Logger.getRootLogger().info(
"Creating logger <" + name + ">");
logger = new LoggerImpl(name);
loggers.put(name, logger);
logger = new LoggerImpl(name);
loggers.put(name, logger);
}
logger.get();
return logger;
return logger;
}
public void releaseLogger(String name) {
@@ -53,8 +53,10 @@
public class SchedulerServiceImpl implements Scheduler {
private static final String START_THREADS_PROPERTY = "eu.sqooss.scheduler.numthreads";
private static final String PERF_LOG_PROPERTY = "eu.sqooss.log.perf";
private Logger logger = null;
private boolean perfLog = false;
private SchedulerStats stats = new SchedulerStats();
@@ -135,7 +137,7 @@ public Job takeJob(Job job) throws SchedulerException {
public void jobStateChanged(Job job, Job.State state) {
if (logger != null) {
logger.info("Job " + job + " changed to state " + state);
logger.debug("Job " + job + " changed to state " + state);
}
if (state == Job.State.Finished) {
@@ -175,7 +177,7 @@ public void startExecute(int n) {
}
for (int i = 0; i < n; ++i) {
WorkerThread t = new WorkerThreadImpl(this);
WorkerThread t = new WorkerThreadImpl(this, i);
t.start();
myWorkerThreads.add(t);
stats.incWorkerThreads();
@@ -241,14 +243,21 @@ public boolean startUp() {
int numThreads = 2 * Runtime.getRuntime().availableProcessors();
String threadsProperty = System.getProperty(START_THREADS_PROPERTY);
if (threadsProperty != null && !threadsProperty.equals("0")) {
if (threadsProperty != null && !threadsProperty.equals("-1")) {
try {
numThreads = Integer.parseInt(threadsProperty);
} catch (NumberFormatException nfe) {
logger.warn("Invalid number of threads to start:" + threadsProperty);
}
}
startExecute(numThreads);
String perfLog = System.getProperty(PERF_LOG_PROPERTY);
if (perfLog != null && perfLog.equals("true")) {
logger.info("Using performance logging");
this.perfLog = true;
}
return true;
}
}
@@ -33,6 +33,7 @@
package eu.sqooss.impl.service.scheduler;
import eu.sqooss.core.AlitheiaCore;
import eu.sqooss.service.scheduler.Job;
import eu.sqooss.service.scheduler.Scheduler;
import eu.sqooss.service.scheduler.SchedulerException;
@@ -43,8 +44,10 @@
*
* @author Christoph Schleifenbaum
*/
class WorkerThreadImpl extends Thread implements WorkerThread
{
class WorkerThreadImpl extends Thread implements WorkerThread {
private static final String PERF_LOG_PROPERTY = "eu.sqooss.log.perf";
private boolean perfLog = false;
private Scheduler m_scheduler;
@@ -58,9 +61,14 @@
* Constructor creating a new WorkerThread
* @param s the schedule being asked for jobs.
*/
public WorkerThreadImpl(Scheduler s) {
super(null, null, "Worker Thread");
public WorkerThreadImpl(Scheduler s, int n) {
super(null, null, "Worker ");
m_scheduler = s;
String perfLog = System.getProperty(PERF_LOG_PROPERTY);
if (perfLog != null && perfLog.equals("true")) {
this.perfLog = true;
}
}
/**
@@ -105,13 +113,19 @@ public Job executedJob() {
protected void executeJob(Job j) {
Job oldJob = m_job;
long time = -1;
try {
m_job = j;
m_job.execute();
time = m_job.execute();
} catch (Exception e) {
// no error handling needed here, the job
// itself takes care of that.
} finally {
if (perfLog) {
AlitheiaCore.getInstance().getLogManager().
createLogger("sqooss.jobtimer").
debug(m_job.toString() + ", time: " + time + " ms");
}
m_job = oldJob;
}
}
@@ -128,7 +142,7 @@ protected void executeJob(Job j) {
private Job job;
public TemporaryWorkerThread(Job job) {
this.worker = new WorkerThreadImpl(null);
this.worker = new WorkerThreadImpl(null, -1);
}
TemporaryWorkerThread(WorkerThreadImpl worker,Job job) {
@@ -171,13 +171,14 @@ public final boolean dependsOn(Job other) {
}
/**
* Executes the job.
* Makes sure, that all dependencies are met.
* Executes the job. Makes sure that all dependencies are met.
*
* @return The time required to execute the Job in milliseconds.
* @throws Exception
*/
final public void execute() throws Exception {
final public long execute() throws Exception {
DBService dbs = AlitheiaCore.getInstance().getDBService();
long timer = System.currentTimeMillis();
try {
setState(State.Running);
restart();
@@ -202,6 +203,7 @@ final public void execute() throws Exception {
// the Exception itself is forwarded
throw e;
}
return System.currentTimeMillis() - timer;
}
/**
@@ -16,7 +16,7 @@ log4j.logger.sqooss.security=WARN
log4j.appender.logfilesqo=org.apache.log4j.RollingFileAppender
log4j.appender.logfilesqo.File=alitheia.log
log4j.appender.logfilesqo.MaxFileSize=1000KB
log4j.appender.logfilesqo.MaxFileSize=10240KB
log4j.appender.logfilesqo.MaxBackupIndex=7
log4j.appender.logfilesqo.layout=org.apache.log4j.PatternLayout
log4j.appender.logfilesqo.layout.ConversionPattern=%p %c - %m%n
@@ -30,7 +30,7 @@ log4j.logger.org.hibernate=INFO,logfilehibernate
log4j.appender.logfilehibernate=org.apache.log4j.RollingFileAppender
log4j.appender.logfilehibernate.File=hibernate.log
log4j.appender.logfilehibernate.MaxFileSize=100KB
log4j.appender.logfilehibernate.MaxFileSize=10240KB
log4j.appender.logfilehibernate.MaxBackupIndex=7
log4j.appender.logfilehibernate.layout=org.apache.log4j.PatternLayout
log4j.appender.logfilehibernate.layout.ConversionPattern=%p %c - %m%n
@@ -41,7 +41,7 @@ log4j.logger.sqooss.webadmin=DEBUG,logfilewebadmin
log4j.additivity.sqooss.webadmin=false
log4j.appender.logfilewebadmin=org.apache.log4j.RollingFileAppender
log4j.appender.logfilewebadmin.File=webadmin.log
log4j.appender.logfilewebadmin.MaxFileSize=1000KB
log4j.appender.logfilewebadmin.MaxFileSize=10240KB
log4j.appender.logfilewebadmin.MaxBackupIndex=7
log4j.appender.logfilewebadmin.layout=org.apache.log4j.PatternLayout
log4j.appender.logfilewebadmin.layout.ConversionPattern=%p %c - %m%n
@@ -61,8 +61,16 @@ log4j.appender.logfileupdater.layout.ConversionPattern=%p - %m%n
log4j.logger.org.jboss.resteasy.core=DEBUG,rest
log4j.appender.rest=org.apache.log4j.RollingFileAppender
log4j.appender.rest.File=rest.log
log4j.appender.rest.MaxFileSize=1000KB
log4j.appender.rest.MaxFileSize=10240KB
log4j.appender.rest.MaxBackupIndex=7
log4j.appender.rest.layout=org.apache.log4j.PatternLayout
log4j.appender.rest.layout.ConversionPattern=%p %c - %m%n
#performance log
log4j.logger.sqooss.jobtimer=DEBUG,perf
log4j.appender.perf=org.apache.log4j.RollingFileAppender
log4j.appender.perf.File=perf.log
log4j.appender.perf.MaxFileSize=20480KB
log4j.appender.perf.MaxBackupIndex=20
log4j.appender.perf.layout=org.apache.log4j.PatternLayout
log4j.appender.perf.layout.ConversionPattern=%d{ISO8601} - %m%n
@@ -190,7 +190,7 @@ private void processList(MailAccessor mailAccessor)
debug("Processing list:" + ml.getListId() + " " + fileNames.size() + " new emails");
for (String fileName : fileNames) {
MailDirJob job = new MailDirJob(ml, fileName, logger);
MailMessageJob job = new MailMessageJob(ml, fileName, logger);
jobs.add(job);
@@ -51,7 +51,7 @@
import eu.sqooss.service.tds.MailAccessor;
import eu.sqooss.service.tds.ProjectAccessor;
public class MailDirJob extends Job{
public class MailMessageJob extends Job{
private static String[] dateFmts = {
"EEE MMM d HH:mm:ss yyyy", //Fri Dec 5 12:50:00 2003
@@ -64,8 +64,9 @@
String fileName;
MailingList ml;
StoredProject project;
int progress = 0;
public MailDirJob(MailingList ml, String f, Logger l) {
public MailMessageJob(MailingList ml, String f, Logger l) {
this.logger = l;
this.ml = ml;
this.fileName = f;
@@ -260,4 +261,10 @@ protected void info(String message) {
protected void debug(String message) {
logger.debug(project.getName() + ":" + message);
}
@Override
public String toString() {
String txt = "MailMessageJob - Message:{" + fileName + "}";
return txt;
}
}
View
@@ -65,6 +65,12 @@
<!-- If fast, only one randomly chosen metric per plug-in will be queried
to determine whether recalculation is necessary. Slow is safer, but, well, slower-->
<eu.sqooss.metricactivator.sync>slow</eu.sqooss.metricactivator.sync>
<!--Output performance information in a seperate log file. Lots of output,
that might hurt performance-->
<eu.sqooss.log.perf>false</eu.sqooss.log.perf>
<!--Start exactly this number of threads. If -1 then the system will use
the default number of threads, currently 2x number of CPUs -->
<eu.sqooss.scheduler.numthreads>-1</eu.sqooss.scheduler.numthreads>
<javax.ws.rs.ext.RuntimeDelegate>org.jboss.resteasy.spi.ResteasyProviderFactory</javax.ws.rs.ext.RuntimeDelegate>
</properties>

0 comments on commit 88a6fcc

Please sign in to comment.