Skip to content

Commit

Permalink
Caching improvements: to avoid repeated feature extraction caching is…
Browse files Browse the repository at this point in the history
… now implemented with a content based hash and not on a path of a file.
  • Loading branch information
JorenSix committed Oct 11, 2022
1 parent 70a3168 commit c2cd1cf
Show file tree
Hide file tree
Showing 22 changed files with 1,021 additions and 372 deletions.
3 changes: 2 additions & 1 deletion resources/defaults/logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ java.util.logging.FileHandler.limit=5000000
# integer to the base file name:
java.util.logging.FileHandler.count=5

# Style of output (Simple or XML):
# Style of output (Simple or XML):
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
4 changes: 2 additions & 2 deletions src/main/java/be/panako/cli/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ protected boolean checkFile(String file){
File f = new File(file);
boolean fileOk = false;
if(f.exists() && f.canRead()){
fileOk = true;
fileOk = FileUtils.checkFileSize(f,Config.getInt(Key.MAX_FILE_SIZE));
}else{
String message = "Could not read " + f.getAbsolutePath() + " it does not exist or is not accesible at the moment.)";
String message = "Could not read " + f.getAbsolutePath() + " it does not exist or is not accessible at the moment.)";
LOG.warning(message);
System.out.println(message);
}
Expand Down
58 changes: 21 additions & 37 deletions src/main/java/be/panako/cli/Delete.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@

import be.panako.strategy.Strategy;
import be.panako.strategy.olaf.OlafStrategy;
import be.panako.util.Config;
import be.panako.util.Key;
import be.panako.util.StopWatch;
import be.panako.util.TimeUnit;
import be.panako.util.*;

/**
* Delete fingerptings from the index.
Expand Down Expand Up @@ -121,42 +118,29 @@ public DeleteTask(File file,int taskID,int totalTasks){
public void run() {

StopWatch w = new StopWatch();
if(checkFile(file)){

Strategy strategy = Strategy.getInstance();

boolean hasResource = false;
hasResource = strategy.hasResource(file.getAbsolutePath());

String message=null;
if(hasResource){
message = String.format("%d/%d;%s;%s;%s",taskID,totalTasks,file.getName(),StopWatch.toTime("", 0),"Deletion skipped: resource not in the key value store;");
}else{
double durationInSeconds = strategy.delete(file.getAbsolutePath());

double cpuSecondsPassed = w.timePassed(TimeUnit.SECONDS);
String audioDuration = StopWatch.toTime("", (int) Math.round(durationInSeconds));
String cpuTimeDuration = w.formattedToString();
double timeRatio = durationInSeconds/cpuSecondsPassed;
message = String.format("%d/%d;%s;%s;%s;%.2f",taskID,totalTasks,file.getName(),audioDuration,cpuTimeDuration,timeRatio);
}
LOG.info(message);
System.out.println(message);
}
}

private boolean checkFile(File file){
boolean fileOk = false;
//file must be smaller than a configured number of bytes
if(file.length() != 0 && file.length() < Config.getInt(Key.MAX_FILE_SIZE)){
fileOk = true;
Strategy strategy = Strategy.getInstance();

boolean hasResource = false;
hasResource = strategy.hasResource(file.getAbsolutePath());

String message=null;
if(hasResource){
message = String.format("%d/%d;%s;%s;%s",taskID,totalTasks,file.getName(),StopWatch.toTime("", 0),"Deletion skipped: resource not in the key value store;");
}else{
String message = "Could not process " + file.getName() + " it has an unacceptable file size: zero or larger than " + Config.getInt(Key.MAX_FILE_SIZE) + "bytes ).";
LOG.warning(message);
System.out.println(message);
double durationInSeconds = strategy.delete(file.getAbsolutePath());

double cpuSecondsPassed = w.timePassed(TimeUnit.SECONDS);
String audioDuration = StopWatch.toTime("", (int) Math.round(durationInSeconds));
String cpuTimeDuration = w.formattedToString();
double timeRatio = durationInSeconds/cpuSecondsPassed;
message = String.format("%d/%d;%s;%s;%s;%.2f",taskID,totalTasks,file.getName(),audioDuration,cpuTimeDuration,timeRatio);
}
return fileOk;
LOG.info(message);
System.out.println(message);

}


}


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/be/panako/cli/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ public void run(String... args) {
if(hasArgument("debug", args) || processors==1){
int taskNumber = 1;
for(File file: files){
new Monitor.MonitorTask(file.getPath(),taskNumber,files.size()).run();
new Monitor.MonitorTask(file.getAbsolutePath(),taskNumber,files.size()).run();
taskNumber++;
}
}else{
ExecutorService executor = Executors.newFixedThreadPool(processors);
int taskNumber = 1;
for(File file: files){
executor.submit(new Monitor.MonitorTask(file.getPath(),taskNumber,files.size()));
executor.submit(new Monitor.MonitorTask(file.getAbsolutePath(),taskNumber,files.size()));
taskNumber++;
}
executor.shutdown();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/be/panako/cli/Print.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void run(String... args) {
Strategy strategy = Strategy.getInstance();

for(File file: files){
strategy.print(file.getPath(),sonicVisualizerOutput);
strategy.print(file.getAbsolutePath(),sonicVisualizerOutput);
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/be/panako/cli/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public void run(String... args) {
if(hasArgument("debug", args) || processors==1){
int taskNumber = 1;
for(File file: files){
new QueryTask(file.getPath(),taskNumber,files.size()).run();
new QueryTask(file.getAbsolutePath(),taskNumber,files.size()).run();
taskNumber++;
}
}else{
ExecutorService executor = Executors.newFixedThreadPool(processors);
int taskNumber = 1;
for(File file: files){
executor.submit(new QueryTask(file.getPath(),taskNumber,files.size()));
executor.submit(new QueryTask(file.getAbsolutePath(),taskNumber,files.size()));
taskNumber++;
}
executor.shutdown();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/be/panako/cli/Resolve.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class Resolve extends Application {

@Override
public void run(String... args) {
Strategy strat = Strategy.getInstance();
Strategy strategy = Strategy.getInstance();
List<File> files = getFilesFromArguments(args);

for(File f : files) {
System.out.println(strat.resolve(f.getPath()));
System.out.println(strategy.resolve(f.getAbsolutePath()));
}
}

Expand Down
61 changes: 20 additions & 41 deletions src/main/java/be/panako/cli/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
import java.util.logging.Logger;

import be.panako.strategy.Strategy;
import be.panako.util.Config;
import be.panako.util.Key;
import be.panako.util.StopWatch;
import be.panako.util.TimeUnit;
import be.panako.util.*;

/**
* Store audio fingerptings in the storage.
Expand Down Expand Up @@ -116,49 +113,31 @@ public StoreTask(File file,int taskID,int totalTasks){

@Override
public void run() {

StopWatch w = new StopWatch();
if(checkFile(file)){

Strategy strategy = Strategy.getInstance();

boolean isDouble = false;
if(Config.getBoolean(Key.CHECK_DUPLICATE_FILE_NAMES) ){
isDouble = strategy.hasResource(file.getAbsolutePath());
}
Strategy strategy = Strategy.getInstance();

String message=null;
if(isDouble){
message = String.format("%d/%d;%s;%s",taskID,totalTasks,file.getName(),"Skipped: resource already stored;");
}else{
double durationInSeconds = strategy.store(file.getAbsolutePath(), file.getName());
double cpuSecondsPassed = w.timePassed(TimeUnit.SECONDS);
String audioDuration = StopWatch.toTime("", (int) Math.round(durationInSeconds));
String cpuTimeDuration = w.formattedToString();
double timeRatio = durationInSeconds/cpuSecondsPassed;
message = String.format("%d/%d;%s;%s;%s;%.2f",taskID,totalTasks,file.getName(),audioDuration,cpuTimeDuration,timeRatio);
}
LOG.info(message);
System.out.println(message);
boolean isDouble = false;
if(Config.getBoolean(Key.CHECK_DUPLICATE_FILE_NAMES) ){
isDouble = strategy.hasResource(file.getAbsolutePath());
}
}

private boolean checkFile(File file){
boolean fileOk = false;

//file must be smaller than a configured number of bytes
long maxFileSize = Config.getInt(Key.MAX_FILE_SIZE);
//from megabytes to bytes
maxFileSize = maxFileSize * 1024 * 1024;
if(file.length() != 0 && file.length() < maxFileSize ){
fileOk = true;

String message=null;
if(isDouble){
message = String.format("%d/%d;%s;%s",taskID,totalTasks,file.getName(),"Skipped: resource already stored;");
}else{
String message = "Could not process " + file.getName() + " it has an unacceptable file size.\n\tFile is " + file.length() + " bytes. \n\tShould be more than zero and smaller than " + Config.getInt(Key.MAX_FILE_SIZE) + " bytes ).";
LOG.warning(message);
System.out.println(message);
double durationInSeconds = strategy.store(file.getAbsolutePath(), file.getName());
double cpuSecondsPassed = w.timePassed(TimeUnit.SECONDS);
String audioDuration = StopWatch.toTime("", (int) Math.round(durationInSeconds));
String cpuTimeDuration = w.formattedToString();
double timeRatio = durationInSeconds/cpuSecondsPassed;
message = String.format("%d/%d;%s;%s;%s;%.2f",taskID,totalTasks,file.getName(),audioDuration,cpuTimeDuration,timeRatio);
}
return fileOk;
LOG.info(message);
System.out.println(message);

}


}


Expand Down
Loading

0 comments on commit c2cd1cf

Please sign in to comment.