From c98678c524a15aa3062d065ed3469668eff02c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kecsk=C3=A9s=20Kriszti=C3=A1n?= <kk1205@sch.bme.hu> Date: Mon, 30 Nov 2015 19:46:55 +0100 Subject: [PATCH] =?UTF-8?q?apr=C3=B3=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- program/Source/app/Application.cpp | 114 ++++++++++++++++++++++++----- program/Source/cache/LFUCache.cpp | 2 +- 2 files changed, 97 insertions(+), 19 deletions(-) diff --git a/program/Source/app/Application.cpp b/program/Source/app/Application.cpp index 77aac8ce..28b1de11 100644 --- a/program/Source/app/Application.cpp +++ b/program/Source/app/Application.cpp @@ -1,5 +1,6 @@ #include <string.h> #include <ctime> +#include <random> #include "../logger/Logger.h" #include "Application.h" #include "../cloud/LocalCloudAdapter.h" @@ -10,6 +11,8 @@ #include "../cache/LRUCache.h" #include "../cache/LFUCache.h" +#include <boost/lexical_cast.hpp> + using namespace std; /** @@ -242,18 +245,20 @@ int main2(int argc, char **argv){ } 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) { FileDescriptor fileDesc = FileDescriptor(fileid); ReturnableFile returned = application.ui.getFile(fileDesc); - if (returned.isValid()) { - cout << "Successfully downloaded: " << returned.getLocalFileId() << endl; - } - else { - cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl; - } + //if (returned.isValid()) { + // cout << "Successfully downloaded: " << returned.getLocalFileId() << endl; + //} + //else { + // cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl; + //} } void getFileList(Application& application) { @@ -279,7 +284,7 @@ int test1(){ application.cm.addCloud(make_shared<LocalCloudAdapter>()); 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 fragFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\temp\\"; @@ -292,7 +297,7 @@ int test1(){ Cache *cacheToSetup; - int cacheSize = 3; + int cacheSize = 16; //cacheToSetup = new NoCache(); cacheToSetup = new FIFOCache(cacheSize); //cacheToSetup = new LRUCache(cacheSize); @@ -310,26 +315,99 @@ int test1(){ application.ui.setComputeOnPi(false); - double elapsed_secs = 0; clock_t begin = clock(); - addFile(application, "1.html", "1h"); - addFile(application, "2.html", "2h"); - addFile(application, "3.html", "3h"); + addFile(application, "1.html", "1.html"); + addFile(application, "2.html", "2.html"); + 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; - deleteFile(application, "1.html"); - deleteFile(application, "2.html"); - deleteFile(application, "3.html"); + for (int i = 0; i<nrolls; ++i) { + if (i % 10 == 0) { + cout << i * 100 / nrolls << "%" << endl; + } + int random1 = -1.0; + int random2 = -1.0; - application.cfs.getCache()->clearCache(); + 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, "2.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(); + + cout << "Out: " << out << endl; cout.precision(15); cout << "Spent time:" << elapsed_secs << endl; - + int i; cin >> i; diff --git a/program/Source/cache/LFUCache.cpp b/program/Source/cache/LFUCache.cpp index ef223028..55f20f70 100644 --- a/program/Source/cache/LFUCache.cpp +++ b/program/Source/cache/LFUCache.cpp @@ -77,7 +77,7 @@ bool LFUCache::addFile(std::string localFileID) { ofstream dst(cacheFolder + localFileID, ios::binary); if (dst) { int minAge = 2147483647; - for (int i = 0; i < minAge; i++) + for (int i = 0; i < maxSize; i++) { if (files[i].used < minAge) { minAge = files[i].used; -- GitLab