Skip to content

Commit

Permalink
Remove unnecessary edge list scan during insert.
Browse files Browse the repository at this point in the history
When a thread reaches the end of the edge list without finding a
spot for the edge it is trying to insert/update, it tries to atomically
swap in a new edge block on the end of the list. If this fails, the
existing code would return to the beginning of the list and re-scan
the entire thing before trying to swap in a new block. With this patch,
the thread just keeps searching from its current position.
  • Loading branch information
ehein6 committed Feb 8, 2017
1 parent 4975d97 commit 260d020
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions lib/stinger_core/inc/stinger_batch_insert.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ class BatchInserter
}

while (next_update() != updates_end) {
eb_index_t * block_ptr = curs.loc;
curs.eb = readff(curs.loc);
/* 2: The edge isn't already there. Check for an empty slot. */
for (stinger_eb *tmp = ebpool_priv + curs.eb; tmp != ebpool_priv; tmp = ebpool_priv + readff(&tmp->next)) {
Expand Down Expand Up @@ -320,19 +319,20 @@ class BatchInserter
if (next_update() == updates_end) { return; }
}
}

block_ptr = &(tmp->next);
// Move the cursor to the next edge block
curs.loc = &(tmp->next);
curs.eb = readff(curs.loc);
}

/* 3: Needs a new block to be inserted at end of list. */
// Try to lock the tail pointer of the last block
eb_index_t old_eb = readfe (block_ptr);
eb_index_t old_eb = readfe (curs.loc);
if (!old_eb) {
// Create a new edge block
eb_index_t newBlock = new_eb (G, type, src);
if (newBlock == 0) {
// Ran out of edge blocks!
writeef (block_ptr, (uint64_t)old_eb);
writeef (curs.loc, (uint64_t)old_eb);
while(next_update() != updates_end)
{
adapter::set_result(*next_update(), EDGE_NOT_ADDED);
Expand All @@ -346,11 +346,11 @@ class BatchInserter
ebpool_priv[newBlock].next = 0;
push_ebs (G, 1, &newBlock);
// Unlock the tail pointer
writeef (block_ptr, (uint64_t)newBlock);
writeef (curs.loc, (uint64_t)newBlock);
}
} else {
// Another thread already added a block, unlock and try again
writeef (block_ptr, (uint64_t)old_eb);
// Another thread already added a block, unlock and keep searching
writeef (curs.loc, (uint64_t)old_eb);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/stinger_core/src/stinger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,6 @@ stinger_update_directed_edge(struct stinger *G,
}

while (1) {
eb_index_t * block_ptr = curs.loc;
curs.eb = readff((uint64_t *)curs.loc);
/* 2: The edge isn't already there. Check for an empty slot. */
for (tmp = ebpool_priv + curs.eb; tmp != ebpool_priv; tmp = ebpool_priv + readff((uint64_t *)&tmp->next)) {
Expand Down Expand Up @@ -1214,25 +1213,26 @@ stinger_update_directed_edge(struct stinger *G,
}
}
}
block_ptr = &(tmp->next);
curs.loc = &(tmp->next);
curs.eb = readff(curs.loc);
}

/* 3: Needs a new block to be inserted at end of list. */
eb_index_t old_eb = readfe ((uint64_t *)block_ptr );
eb_index_t old_eb = readfe (curs.loc);
if (!old_eb) {
eb_index_t newBlock = new_eb (G, type, src);
if (newBlock == 0) {
writeef ((uint64_t *)block_ptr, (uint64_t)old_eb);
writeef (curs.loc, (uint64_t)old_eb);
return -1;
} else {
update_edge_data_and_direction (G, ebpool_priv + newBlock, 0, dest, weight, timestamp, direction, EDGE_WEIGHT_SET);
ebpool_priv[newBlock].next = 0;
push_ebs (G, 1, &newBlock);
}
writeef ((uint64_t *)block_ptr, (uint64_t)newBlock);
writeef (curs.loc, (uint64_t)newBlock);
return 1;
}
writeef ((uint64_t *)block_ptr, (uint64_t)old_eb);
writeef (curs.loc, (uint64_t)old_eb);
}


Expand Down

0 comments on commit 260d020

Please sign in to comment.