Skip to content
Snippets Groups Projects
Commit d7a79bdd authored by Florian Fischer's avatar Florian Fischer
Browse files

do not parallelize searching and use smaller buffers

parent 6befa43b
No related branches found
No related tags found
No related merge requests found
Pipeline #80388 failed
......@@ -3,7 +3,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <array>
#include <atomic>
#include <boost/program_options.hpp>
#include <cstdlib>
......@@ -26,7 +25,6 @@
namespace fs = std::filesystem;
namespace po = boost::program_options;
#define EMPER_READ_BUFSIZE 65536
#define EMPER_SEARCH_BUFSIZE 4096
static const char* needle;
......@@ -37,17 +35,11 @@ static emper::Semaphore* max_open;
static emper::lib::ShardedFileBuffer* outBuf;
void searchPart(const char* buf, size_t len, std::atomic<bool>* found) {
if (found->load(std::memory_order_consume)) return;
if (memmem(buf, len, needle, needle_len)) found->store(true, std::memory_order_release);
}
// NOLINTNEXTLINE(clang-diagnostic-unknown-attributes)
emper_fibril void search(const std::string& path) {
emper::io::RegisteredFile file;
auto* buf = new std::array<char, EMPER_READ_BUFSIZE>;
char buf[EMPER_SEARCH_BUFSIZE];
emper::io::OpenFuture openFuture(file, path.c_str(), O_RDONLY);
int res = openFuture.submitAndWait();
......@@ -55,7 +47,7 @@ emper_fibril void search(const std::string& path) {
DIE_MSG("opening " << path << " failed:" << strerror(-res));
}
emper::io::ReadFuture readFuture(file, buf->data(), buf->size(), 0);
emper::io::ReadFuture readFuture(file, buf, sizeof(buf), 0);
// readFuture.setDependency(openFuture);
int bytes_read = readFuture.submitAndWait();
......@@ -68,29 +60,12 @@ emper_fibril void search(const std::string& path) {
// }
while (bytes_read > 0) {
// Parallel searching
std::atomic<bool> found = false;
{
const size_t parts = bytes_read / EMPER_SEARCH_BUFSIZE + 1;
Fibril fibril;
for (size_t i = 0; i < parts; ++i) {
const size_t partBegin = i * EMPER_SEARCH_BUFSIZE;
const char* partBuf = &(*buf)[partBegin];
const size_t partLen = (i < parts - 1) ? EMPER_SEARCH_BUFSIZE : bytes_read - partBegin;
fibril.spawn(searchPart, partBuf, partLen, &found);
}
// The fibril is implicitly joined when dropped
}
if (found.load(std::memory_order_acquire)) {
if (memmem(buf, bytes_read, needle, needle_len)) {
outBuf->getStream() << path << std::endl;
goto out;
return;
}
emper::io::ReadFuture readFuture(file, buf->data(), buf->size(), -1);
emper::io::ReadFuture readFuture(file, buf, sizeof(buf), -1);
bytes_read = readFuture.submitAndWait();
}
......@@ -98,9 +73,6 @@ emper_fibril void search(const std::string& path) {
DIE_MSG("read of " << path << " failed: " << strerror(-bytes_read));
}
out:
delete buf;
// We do not need to close registered files they are closed automatically if a
// new file is registered at their slot.
// And the slot is returned when the RegisteredFile is dropped.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment