Skip to content
Snippets Groups Projects
Commit c98678c5 authored by kk1205's avatar kk1205
Browse files

apró fix

parent ec5a2bd4
No related branches found
No related tags found
No related merge requests found
#include <string.h> #include <string.h>
#include <ctime> #include <ctime>
#include <random>
#include "../logger/Logger.h" #include "../logger/Logger.h"
#include "Application.h" #include "Application.h"
#include "../cloud/LocalCloudAdapter.h" #include "../cloud/LocalCloudAdapter.h"
...@@ -10,6 +11,8 @@ ...@@ -10,6 +11,8 @@
#include "../cache/LRUCache.h" #include "../cache/LRUCache.h"
#include "../cache/LFUCache.h" #include "../cache/LFUCache.h"
#include <boost/lexical_cast.hpp>
using namespace std; using namespace std;
/** /**
...@@ -242,18 +245,20 @@ int main2(int argc, char **argv){ ...@@ -242,18 +245,20 @@ int main2(int argc, char **argv){
} }
void addFile(Application& application, string localid, string destid) { void addFile(Application& application, string localid, string destid) {
cout << application.ui.addFile(localid, destid) << endl; //cout <<
application.ui.addFile(localid, destid);
//<< endl;
} }
void getFile(Application& application, string fileid) { void getFile(Application& application, string fileid) {
FileDescriptor fileDesc = FileDescriptor(fileid); FileDescriptor fileDesc = FileDescriptor(fileid);
ReturnableFile returned = application.ui.getFile(fileDesc); ReturnableFile returned = application.ui.getFile(fileDesc);
if (returned.isValid()) { //if (returned.isValid()) {
cout << "Successfully downloaded: " << returned.getLocalFileId() << endl; // cout << "Successfully downloaded: " << returned.getLocalFileId() << endl;
} //}
else { //else {
cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl; // cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl;
} //}
} }
void getFileList(Application& application) { void getFileList(Application& application) {
...@@ -279,7 +284,7 @@ int test1(){ ...@@ -279,7 +284,7 @@ int test1(){
application.cm.addCloud(make_shared<LocalCloudAdapter>()); application.cm.addCloud(make_shared<LocalCloudAdapter>());
application.cm.addCloud(make_shared<DropboxAdapter>()); application.cm.addCloud(make_shared<DropboxAdapter>());
application.cm.addCloud(make_shared<FTPAdapter>()); //application.cm.addCloud(make_shared<FTPAdapter>());
string dataFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\data\\"; string dataFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\data\\";
string fragFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\temp\\"; string fragFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\temp\\";
...@@ -292,7 +297,7 @@ int test1(){ ...@@ -292,7 +297,7 @@ int test1(){
Cache *cacheToSetup; Cache *cacheToSetup;
int cacheSize = 3; int cacheSize = 16;
//cacheToSetup = new NoCache(); //cacheToSetup = new NoCache();
cacheToSetup = new FIFOCache(cacheSize); cacheToSetup = new FIFOCache(cacheSize);
//cacheToSetup = new LRUCache(cacheSize); //cacheToSetup = new LRUCache(cacheSize);
...@@ -310,23 +315,96 @@ int test1(){ ...@@ -310,23 +315,96 @@ int test1(){
application.ui.setComputeOnPi(false); application.ui.setComputeOnPi(false);
double elapsed_secs = 0;
clock_t begin = clock(); clock_t begin = clock();
addFile(application, "1.html", "1h"); addFile(application, "1.html", "1.html");
addFile(application, "2.html", "2h"); addFile(application, "2.html", "2.html");
addFile(application, "3.html", "3h"); addFile(application, "3.html", "3.html");
addFile(application, "4.html", "4.html");
addFile(application, "5.html", "5.html");
addFile(application, "6.html", "6.html");
addFile(application, "7.html", "7.html");
addFile(application, "8.html", "8.html");
addFile(application, "9.html", "9.html");
addFile(application, "10.html", "10.html");
addFile(application, "11.html", "11.html");
addFile(application, "12.html", "12.html");
addFile(application, "13.html", "13.html");
addFile(application, "14.html", "14.html");
addFile(application, "15.html", "15.html");
addFile(application, "16.html", "16.html");
addFile(application, "17.html", "17.html");
addFile(application, "18.html", "18.html");
addFile(application, "19.html", "19.html");
addFile(application, "20.html", "20.html");
std::default_random_engine generator;
std::normal_distribution<double> distribution(10.0, 4.0);
const int nrolls = 300; // number of experiments
const double nfiles = 20.0; // number of files
int out = 0;
double elapsed_secs = 0;
for (int i = 0; i<nrolls; ++i) {
if (i % 10 == 0) {
cout << i * 100 / nrolls << "%" << endl;
}
int random1 = -1.0;
int random2 = -1.0;
double number1 = distribution(generator);
if ((number1 >= 0.0) && (number1 < nfiles)) {
random1 = int(number1);
}
else {
out++;
}
double number2 = distribution(generator);
if ((number2 >= 0.0) && (number2 < nfiles)) {
random2 = int(number2);
}
else {
out++;
}
if (random1 > 0 && random2 > 0 && random1 < 20 && random2 < 20) {
string file1 = boost::lexical_cast<string>(random1)+".html";
string file2 = boost::lexical_cast<string>(random2)+".html";
addFile(application, file1, file1);
getFile(application, file2);
}
}
clock_t end = clock();
elapsed_secs += double(end - begin);
deleteFile(application, "1.html"); deleteFile(application, "1.html");
deleteFile(application, "2.html"); deleteFile(application, "2.html");
deleteFile(application, "3.html"); deleteFile(application, "3.html");
deleteFile(application, "4.html");
deleteFile(application, "5.html");
deleteFile(application, "6.html");
deleteFile(application, "7.html");
deleteFile(application, "8.html");
deleteFile(application, "9.html");
deleteFile(application, "10.html");
deleteFile(application, "11.html");
deleteFile(application, "12.html");
deleteFile(application, "13.html");
deleteFile(application, "14.html");
deleteFile(application, "15.html");
deleteFile(application, "16.html");
deleteFile(application, "17.html");
deleteFile(application, "18.html");
deleteFile(application, "19.html");
deleteFile(application, "20.html");
application.cfs.getCache()->clearCache(); application.cfs.getCache()->clearCache();
clock_t end = clock(); cout << "Out: " << out << endl;
elapsed_secs += double(end - begin);
cout.precision(15); cout.precision(15);
cout << "Spent time:" << elapsed_secs << endl; cout << "Spent time:" << elapsed_secs << endl;
......
...@@ -77,7 +77,7 @@ bool LFUCache::addFile(std::string localFileID) { ...@@ -77,7 +77,7 @@ bool LFUCache::addFile(std::string localFileID) {
ofstream dst(cacheFolder + localFileID, ios::binary); ofstream dst(cacheFolder + localFileID, ios::binary);
if (dst) { if (dst) {
int minAge = 2147483647; int minAge = 2147483647;
for (int i = 0; i < minAge; i++) for (int i = 0; i < maxSize; i++)
{ {
if (files[i].used < minAge) { if (files[i].used < minAge) {
minAge = files[i].used; minAge = files[i].used;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment