Skip to content

Commit

Permalink
playing with scaling policy
Browse files Browse the repository at this point in the history
  • Loading branch information
e0756024 committed Nov 24, 2013
1 parent a0b710d commit 104d35a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static CloudScaleConfiguration localConfig() {

CloudScaleConfiguration cfg = CloudScaleConfigurationBuilder
.createLocalConfigurationBuilder()
.withGlobalLoggingLevel(Level.INFO)
.withGlobalLoggingLevel(Level.WARNING)
.with(new ScalingPolicy())
.withMonitoring(true)
.withMonitoringEvents(TestEvent.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
package at.ac.tuwien.infosys.aic13.cloudscale.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.ac.tuwien.infosys.aic13.cloudscale.service.SentimentAnalysisService;
import at.ac.tuwien.infosys.aic13.cloudscale.workers.DummyWorker;
import at.ac.tuwien.infosys.aic13.publicdto.PublicSentimentQuery;
import at.ac.tuwien.infosys.aic13.publicdto.PublicSentimentQueryResult;

public class SentimentAnalysisServiceDummyImpl extends SentimentAnalysisService {
@Override
public void runSentimentAnalysis(){
SentimentAnalysisRunner runner = new SentimentAnalysisRunner();
Thread t = new Thread(runner);
t.start();
}

private class SentimentAnalysisRunner implements Runnable{

@Override
public void run() {
PublicSentimentQuery publicQuery = getNextQuery();
if(publicQuery == null) return;

// Creating and starting a worker... this runs through AOP eaving n cloudscale.
DummyWorker worker = new DummyWorker();
PublicSentimentQueryResult publicResult = worker.doTheAnalysisStuff(publicQuery);
publicResult.setQueryId(publicQuery.getQueryId());
writeResult(publicResult);

}

}

private static final Logger log = LoggerFactory.getLogger(SentimentAnalysisServiceDummyImpl.class);

@Override
public void runSentimentAnalysis(){
SentimentAnalysisRunner runner = new SentimentAnalysisRunner();
Thread t = new Thread(runner);
t.setDaemon(true);
t.start();
}

private class SentimentAnalysisRunner implements Runnable{

@Override
public void run() {
PublicSentimentQuery publicQuery = getNextQuery();
if(publicQuery == null) return;

// Creating and starting a worker... this runs through AOP eaving n cloudscale.
DummyWorker worker = new DummyWorker();
PublicSentimentQueryResult publicResult = worker.doTheAnalysisStuff(publicQuery);
publicResult.setQueryId(publicQuery.getQueryId());
writeResult(publicResult);

}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package at.ac.tuwien.infosys.aic13.cloudscale.workers;

import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.ac.tuwien.infosys.aic13.Utils;
import at.ac.tuwien.infosys.aic13.publicdto.PublicSentimentQuery;
import at.ac.tuwien.infosys.aic13.publicdto.PublicSentimentQueryResult;
Expand All @@ -8,18 +14,25 @@

@CloudObject
public class DummyWorker {

private static final Logger log = LoggerFactory.getLogger(DummyWorker.class);

@DestructCloudObject
public PublicSentimentQueryResult doTheAnalysisStuff(PublicSentimentQuery query){

@DestructCloudObject
public PublicSentimentQueryResult doTheAnalysisStuff(PublicSentimentQuery query){
try {
Thread.sleep(Utils.getRandom(250, 5000));
} catch (InterruptedException e) {

}

PublicSentimentQueryResult result = new PublicSentimentQueryResult();
result.setNumberOfTweets(Utils.getRandom(10, 1000));
result.setSentimentValue(Math.random());
return result;
long randomSleepTime = ThreadLocalRandom.current().nextLong(10000);
long startTime = System.currentTimeMillis();
log.info(
String.format("DummyWorker will now prodcue CPU Load for %d seconds",
TimeUnit.MILLISECONDS.toSeconds(randomSleepTime)));
while ((System.currentTimeMillis() - startTime) < randomSleepTime) {
//produce CPU load while waiting
}


PublicSentimentQueryResult result = new PublicSentimentQueryResult();
result.setNumberOfTweets(Utils.getRandom(10, 1000));
result.setSentimentValue(Math.random());
return result;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

<!-- Root Logger -->
<root>
<priority value="debug" />
<priority value="info" />
<appender-ref ref="console" />
<!-- <appender-ref ref="file" /> -->
</root>
Expand Down

0 comments on commit 104d35a

Please sign in to comment.