Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions source/utils/xrootd-plugin/AdiosFilePool.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "AdiosFilePool.h"
#include <iostream>
#include <thread>

namespace adios2
{
Expand Down Expand Up @@ -64,23 +66,61 @@ void ADIOSFilePool::SubPool::Return(adios2::AnonADIOSFile *to_free)
std::cerr << "Return FAILED " << std::endl;
}

ADIOSFilePool::ADIOSFilePool() {}
void ADIOSFilePool::DoTimeoutTasks() { FlushUnused(); }

void ADIOSFilePool::PeriodicTask(std::chrono::milliseconds interval)
{
while (!(m_ShutdownFlag))
{
DoTimeoutTasks();
std::this_thread::sleep_for(interval);
}
std::cout << "Clean shutdown of ADIOSFilePool periodic thread" << std::endl;
}

ADIOSFilePool::ADIOSFilePool()
{
std::cout << "Singleton ADIOSFilePool instance created.\n";
periodicThread = periodicWorker();
}

ADIOSFilePool &ADIOSFilePool::getInstance()
{
static ADIOSFilePool instance; // Guaranteed to be destroyed.
// Instantiated on first use.
return instance;
}

void ADIOSFilePool::FlushUnused()
{
auto now = std::chrono::steady_clock::now();
for (auto it = map.cbegin(), next_it = it; it != map.cend(); it = next_it)
{
++next_it;
auto subpool = it->second.get();
bool should_delete = (subpool->in_use_count == 0);

auto unused_duration = now - subpool->last_used;
auto elapsed_seconds =
std::chrono::duration_cast<std::chrono::seconds>(unused_duration).count();
bool should_delete = (elapsed_seconds > 15) && (subpool->in_use_count == 0);
std::string fname = "";
if (subpool->m_list.size() > 0)
fname = subpool->m_list[0]->m_FileName;
if (should_delete)
{
std::cout << "Releasing subpool" << std::endl;
if (subpool->m_list.size() > 0)
std::cout << "Releasing subpool for file \"" << subpool->m_list[0]->m_FileName
<< "\" unused for " << elapsed_seconds << " seconds" << std::endl;
map.erase(it);
}
}
}

ADIOSFilePool::~ADIOSFilePool() {}
ADIOSFilePool::~ADIOSFilePool()
{
m_ShutdownFlag = true;
if (periodicThread.joinable())
{
periodicThread.join();
}
}
} // end of namespace adios2
23 changes: 21 additions & 2 deletions source/utils/xrootd-plugin/AdiosFilePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

/// \cond EXCLUDE_FROM_DOXYGEN
#include <algorithm>
#include <atomic>
#include <cstring>
#include <mutex>
#include <random>
#include <string>
#include <thread>
#include <vector>
/// \endcond

Expand Down Expand Up @@ -75,18 +77,35 @@ class AnonADIOSFile
}
};

// singleton
class ADIOSFilePool
{

public:
ADIOSFilePool();
static ADIOSFilePool &getInstance();
~ADIOSFilePool();

AnonADIOSFile *GetFree(std::string Filename, bool RowMajorArrays);
void Return(AnonADIOSFile *Entry);
void FlushUnused();

private:
static ADIOSFilePool *instance;

// Private constructor
ADIOSFilePool();

// Delete copy constructor and assignment
ADIOSFilePool(const ADIOSFilePool &) = delete;
ADIOSFilePool &operator=(const ADIOSFilePool &) = delete;

void PeriodicTask(std::chrono::milliseconds interval);
void DoTimeoutTasks();
std::atomic<bool> m_ShutdownFlag{false};
std::thread periodicWorker()
{
return std::thread([=] { PeriodicTask(std::chrono::milliseconds(1000)); });
}
std::thread periodicThread;
class SubPool
{

Expand Down
2 changes: 1 addition & 1 deletion source/utils/xrootd-plugin/XrdSsiSvService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void XrdSsiSvService::ProcessRequest(XrdSsiRequest &reqRef, XrdSsiResource &resR
// efficient ways of doing this (e.g. a dedicated task object) but this is OK.
// The agent will delete itself when the request is actually finished.
//
agent = new XrdSsiSvService(resRef.rName.c_str(), &m_ParentFilePool);
agent = new XrdSsiSvService(resRef.rName.c_str());
agent->ProcessRequest4Me(&reqRef);
}
XrdSsiSvService::~XrdSsiSvService()
Expand Down
10 changes: 1 addition & 9 deletions source/utils/xrootd-plugin/XrdSsiSvService.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ public:
*m_respMeta = 0;
}

XrdSsiSvService(const char *sname, ADIOSFilePool *parentPoolPointer = NULL)
{
sName = strdup(sname ? sname : "");
*m_respMeta = 0;
m_FilePoolPtr = parentPoolPointer;
}

protected:
//-----------------------------------------------------------------------------
//! Notify a service that a request either completed or was canceled. This
Expand Down Expand Up @@ -114,7 +107,6 @@ private:
char m_respData[1024];
int streamRdSz;
bool streamActv;
adios2::ADIOSFilePool m_ParentFilePool; // unused except in parent object
adios2::ADIOSFilePool *m_FilePoolPtr; // pointer to parent object pool
adios2::ADIOSFilePool *m_FilePoolPtr = &adios2::ADIOSFilePool::getInstance();
};
#endif
Loading