Skip to content

Commit

Permalink
shared storage cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshkaj committed Apr 1, 2018
1 parent 3ae343c commit e57c949
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions include/engine/search_engine_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>

using SearchEngineHeapPtr = boost::thread_specific_ptr<QueryHeap>;
using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>;
using UnpackingCachePtr = boost::thread_specific_ptr<UnpackingCache>;
using UnpackingCachePtr = std::unique_ptr<UnpackingCache>; // do I need to make this threadsafe?

static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1;
Expand All @@ -66,7 +66,7 @@ template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>

void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes);

void InitializeOrClearUnpackingCacheThreadLocalStorage(unsigned timestamp);
void InitializeOrClearUnpackingCacheGlobalStorage(unsigned timestamp);
};

struct MultiLayerDijkstraHeapData
Expand Down
24 changes: 15 additions & 9 deletions include/engine/unpacking_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,40 @@ namespace engine
class UnpackingCache
{
private:
boost::compute::detail::lru_cache<std::tuple<NodeID, NodeID, std::size_t>, EdgeDuration> cache;
unsigned current_data_timestamp = 0;
boost::compute::detail::lru_cache<std::tuple<NodeID, NodeID, std::size_t>, EdgeDuration>
m_cache;
unsigned m_current_data_timestamp = 0;
std::mutex m_mutex;

public:
UnpackingCache(unsigned timestamp) : cache(6000000), current_data_timestamp(timestamp){};
UnpackingCache(unsigned timestamp) : m_cache(6000000), m_current_data_timestamp(timestamp){};

void Clear(unsigned new_data_timestamp)
{
if (current_data_timestamp != new_data_timestamp)
std::lock_guard<std::mutex> guard(m_mutex);
if (m_current_data_timestamp != new_data_timestamp)
{
cache.clear();
current_data_timestamp = new_data_timestamp;
m_cache.clear();
m_current_data_timestamp = new_data_timestamp;
}
}

bool IsEdgeInCache(std::tuple<NodeID, NodeID, std::size_t> edge)
{
return cache.contains(edge);
std::lock_guard<std::mutex> guard(m_mutex);
return m_cache.contains(edge);
}

void AddEdge(std::tuple<NodeID, NodeID, std::size_t> edge, EdgeDuration duration)
{
cache.insert(edge, duration);
std::lock_guard<std::mutex> guard(m_mutex);
m_cache.insert(edge, duration);
}

EdgeDuration GetDuration(std::tuple<NodeID, NodeID, std::size_t> edge)
{
boost::optional<EdgeDuration> duration = cache.get(edge);
std::lock_guard<std::mutex> guard(m_mutex);
boost::optional<EdgeDuration> duration = m_cache.get(edge);
return *duration ? *duration : MAXIMAL_EDGE_DURATION;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/engine/routing_algorithms/many_to_many_ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ std::vector<EdgeDuration> manyToManySearch(SearchEngineData<ch::Algorithm> &engi
std::vector<NodeBucket> search_space_with_buckets;
std::vector<NodeID> packed_leg;

engine_working_data.InitializeOrClearUnpackingCacheThreadLocalStorage(
engine_working_data.InitializeOrClearUnpackingCacheGlobalStorage(
facade.GetTimestamp()); // always pass in the timestamp and clear if it's different

// Populate buckets with paths from all accessible nodes to destinations via backward searches
Expand Down
5 changes: 4 additions & 1 deletion src/engine/search_engine_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ void SearchEngineData<CH>::InitializeOrClearManyToManyThreadLocalStorage(unsigne
}
}

void SearchEngineData<CH>::InitializeOrClearUnpackingCacheThreadLocalStorage(unsigned timestamp)
void SearchEngineData<CH>::InitializeOrClearUnpackingCacheGlobalStorage(unsigned timestamp)
{
// using UnpackingCachePtr = std::unique_ptr<UnpackingCache>; // do I need to make this
// threadsafe?
// because of effects here
if (unpacking_cache.get())
{
unpacking_cache->Clear(timestamp);
Expand Down

0 comments on commit e57c949

Please sign in to comment.