Skip to content

Commit

Permalink
new method to cleanup the table and performance upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
AP-Frank committed Jul 2, 2018
1 parent bcbc9ca commit bf50ecc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
20 changes: 13 additions & 7 deletions examples/moonsniff/tbbmatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,16 @@ function addKeyVal(cap, keyBuf, tsBuf, entryBuf)

acc:release()

-- tbbmap:clean(100000000000)

-- log:info("deque")

-- add data to the deque
-- local entry = C.malloc(ffi.sizeof(ffi.typeof("struct deque_entry")))
-- local entry = ffi.new("struct deque_entry", {});
ffi.copy(entryBuf.key, keyBuf, 16)
ffi.copy(entryBuf.timestamp, tsBuf, 8)
C.deque_push_front(deque, entryBuf)
-- ffi.copy(entryBuf.key, keyBuf, 16)
-- ffi.copy(entryBuf.timestamp, tsBuf, 8)
-- C.deque_push_front(deque, entryBuf)
end

function getKeyVal(cap, misses, keyBuf, tsBuf, lastHit)
Expand All @@ -236,19 +238,20 @@ function getKeyVal(cap, misses, keyBuf, tsBuf, lastHit)
local diff = post_ts[0] - pre_ts[0]
C.hs_update(diff)

lastHit = post_ts[0]
-- lastHit = post_ts[0]

-- log:info("Diff: " .. tostring(diff))

-- delete associated data
tbbmap:erase(acc)
-- tbbmap:erase(acc)

acc:release()
else
misses = misses + 1
end

releaseOld(lastHit)
-- releaseOld(lastHit)
-- tbbmap:clean(100000000000)
return misses, lastHit
end

Expand Down Expand Up @@ -303,9 +306,12 @@ function tbbCore(args, PRE, POST)
sfree(precap)
-- log:info("freeing")
precap = readSingle(prereader)
ctr = ctr - 1
end

log:info("done prefilling")
tbbmap:clean(1000000000000)

log:info("clean")

local postcap = readSingle(postreader)
local misses = 0
Expand Down
4 changes: 4 additions & 0 deletions lua/hmap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bool hmapk{key_size}v{value_size}_access(hmapk{key_size}v{value_size}* map, hmap
bool hmapk{key_size}v{value_size}_find(hmapk{key_size}v{value_size}* map, hmapk{key_size}v{value_size}_accessor* a, const void* key);
bool hmapk{key_size}v{value_size}_erase(hmapk{key_size}v{value_size}* map, hmapk{key_size}v{value_size}_accessor* a);
uint8_t* hmapk{key_size}v{value_size}_accessor_get_value(hmapk{key_size}v{value_size}_accessor* a);
void hmapk{key_size}v{value_size}_clean(hmapk{key_size}v{value_size}* map, uint64_t threash);
]]

local module = {}
Expand Down Expand Up @@ -76,6 +77,9 @@ function makeHashmapFor(keySize, valueSize)
function map.valueSize()
return valueSize
end
function map:clean(threash)
return C["hmapk" .. keySize .. "v" .. valueSize .. "_clean"](self, threash)
end
local accessor = {}
function accessor:get()
return C["hmapk" .. keySize .. "v" .. valueSize .. "_accessor_get_value"](self)
Expand Down
17 changes: 17 additions & 0 deletions src/hashmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cstdint>
#include <iostream>
#include <c_bindings.h>
#include <deque>

namespace hash_map {
/* Secret hash cookie */
Expand Down Expand Up @@ -90,6 +91,22 @@ using namespace hash_map;
} \
bool hmapk##key_size##v##value_size##_find(hmapk##key_size##v##value_size* map, hmapk##key_size##v##value_size::accessor* a, const void* key) { \
return map->find(*a, *static_cast<const K<key_size>*>(key)); \
} \
void hmapk##key_size##v##value_size##_clean(hmapk##key_size##v##value_size* map, uint64_t thresh) { \
int ctr = 0; \
std::deque<hash_map::key_buf<key_size>> deque; \
for (hmapk##key_size##v##value_size::iterator it = map->begin(); it != map->end();) { \
std::cout << ++ctr << "\n"; \
uint64_t ts = *reinterpret_cast<uint64_t *>( &(*it).second); \
if(ts < thresh) { \
deque.push_front(it->first); \
} \
it++; \
for(auto it = deque.begin(); it != deque.end(); it++) { \
map->erase(*it); \
} \
} \
deque.clear(); \
}

#define MAP_VALUES(value_size) \
Expand Down

0 comments on commit bf50ecc

Please sign in to comment.