-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from spacetelescope/feature/messaging_system
Variable size buffer management
- Loading branch information
Showing
10 changed files
with
1,285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#include "FreeListAllocator.h" | ||
#include "Timing.h" | ||
#include <iostream> | ||
|
||
void benchmark_linux_scalability() | ||
{ | ||
const size_t N = 10000000; | ||
|
||
const size_t NUM_BLOCKS = N * 2; | ||
const size_t ALIGNMENT = 32; | ||
|
||
auto *handles = new FreeListAllocator::BlockHandle[N]; | ||
|
||
size_t buffer_size = FreeListAllocator::ComputeMetadataBufferSize(NUM_BLOCKS); | ||
char *buffer = new char[buffer_size]; | ||
|
||
auto allocator = FreeListAllocator::Create(buffer, NUM_BLOCKS, ALIGNMENT, NUM_BLOCKS * ALIGNMENT); | ||
|
||
auto start = GetTimeStamp(); | ||
|
||
for (size_t i = 0; i < N; ++i) | ||
{ | ||
handles[i] = allocator->Allocate(16); | ||
} | ||
|
||
for (size_t i = 0; i < N; ++i) | ||
{ | ||
allocator->Deallocate(handles[i]); | ||
} | ||
|
||
auto end = GetTimeStamp(); | ||
|
||
std::cout << "Linux Scalability:" << std::endl; | ||
std::cout << "Time: " << (end - start) / 1e9 << " sec" << std::endl; | ||
std::cout << "Throughput: " << 2 * N / ((end - start) / 1e9) << " ops/s" << std::endl; | ||
std::cout << "Time per operation: " << (end - start) / (2 * N) << " ns" << std::endl; | ||
|
||
delete[] handles; | ||
delete[] buffer; | ||
} | ||
|
||
void benchmark_threadtest() | ||
{ | ||
const size_t N = 100; | ||
const size_t M = 100000; | ||
const size_t NUM_BLOCKS = N * 2; | ||
const size_t ALIGNMENT = 32; | ||
|
||
auto *handles = new FreeListAllocator::BlockHandle[M]; | ||
|
||
size_t buffer_size = FreeListAllocator::ComputeMetadataBufferSize(NUM_BLOCKS); | ||
char *buffer = new char[buffer_size]; | ||
|
||
auto allocator = FreeListAllocator::Create(buffer, NUM_BLOCKS, ALIGNMENT, NUM_BLOCKS * ALIGNMENT); | ||
|
||
auto start = GetTimeStamp(); | ||
|
||
for (size_t i = 0; i < M; ++i) | ||
{ | ||
for (size_t j = 0; j < N; ++j) | ||
{ | ||
handles[j] = allocator->Allocate(16); | ||
} | ||
|
||
for (size_t j = 0; j < N; ++j) | ||
{ | ||
allocator->Deallocate(handles[j]); | ||
} | ||
} | ||
|
||
auto end = GetTimeStamp(); | ||
|
||
std::cout << "Threadtest:" << std::endl; | ||
std::cout << "Time: " << (end - start) / 1e9 << " sec" << std::endl; | ||
std::cout << "Throughput: " << 2 * N * M / ((end - start) / 1e9) << " ops/s" << std::endl; | ||
std::cout << "Time per operation: " << (end - start) / (2 * N * M) << " ns" << std::endl; | ||
|
||
delete[] handles; | ||
} | ||
|
||
void benchmark_larson() | ||
{ | ||
const size_t ALIGNMENT = 32; | ||
|
||
const size_t N = 10000000; | ||
const size_t M = 1000; | ||
const size_t MIN_SIZE = 16; | ||
const size_t MAX_SIZE = 128; | ||
const size_t NUM_BLOCKS = M * 2; | ||
|
||
auto *handles = new FreeListAllocator::BlockHandle[M]; | ||
for (size_t i = 0; i < M; ++i) | ||
{ | ||
handles[i] = -1; | ||
} | ||
|
||
size_t buffer_size = FreeListAllocator::ComputeMetadataBufferSize(NUM_BLOCKS); | ||
char *buffer = new char[buffer_size]; | ||
|
||
auto allocator = FreeListAllocator::Create(buffer, NUM_BLOCKS, ALIGNMENT, MAX_SIZE * NUM_BLOCKS); | ||
|
||
auto *indices = new size_t[N]; | ||
auto *sizes = new size_t[N]; | ||
for (size_t i = 0; i < N; ++i) | ||
{ | ||
indices[i] = rand() % M; | ||
sizes[i] = (MIN_SIZE + (rand() % (MAX_SIZE - MIN_SIZE))) * ALIGNMENT; | ||
} | ||
|
||
auto start = GetTimeStamp(); | ||
|
||
for (size_t i = 0; i < N; ++i) | ||
{ | ||
size_t index = indices[i]; | ||
size_t size = sizes[i]; | ||
|
||
if (handles[index] != -1) | ||
{ | ||
allocator->Deallocate(handles[index]); | ||
} | ||
|
||
handles[index] = allocator->Allocate(size); | ||
} | ||
|
||
auto end = GetTimeStamp(); | ||
std::cout << "Larson benchmark:" << std::endl; | ||
std::cout << "Time: " << (end - start) / 1e9 << " sec" << std::endl; | ||
std::cout << "Throughput: " << (N * 2 - M) / ((end - start) / 1e9) << " ops/s" << std::endl; | ||
std::cout << "Time per operation: " << (end - start) / (2 * N - M) << " ns" << std::endl; | ||
|
||
delete[] handles; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
benchmark_linux_scalability(); | ||
benchmark_threadtest(); | ||
benchmark_larson(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "HashMap.h" | ||
#include "Timing.h" | ||
|
||
#include <iostream> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
typedef HashMap<uint16_t, 16384, 13> MyHashMap; | ||
|
||
std::size_t buffer_size = MyHashMap::CalculateBufferSize(); | ||
std::cout << "Buffer size: " << buffer_size << " bytes" << std::endl; | ||
char *buffer = new char[buffer_size]; | ||
|
||
MyHashMap map(buffer); | ||
map.Initialize(); | ||
|
||
std::uint64_t total_time = 0; | ||
std::size_t N = 5000; | ||
|
||
for (size_t i = 0; i < N; ++i) | ||
{ | ||
std::string key = "key" + std::to_string(i); | ||
|
||
auto start = GetTimeStamp(); | ||
bool success = map.Insert(key, uint16_t(i)); | ||
auto end = GetTimeStamp(); | ||
|
||
if (!success) | ||
{ | ||
std::cout << "Insertion failed." << std::endl; | ||
} | ||
|
||
total_time += end - start; | ||
} | ||
|
||
std::cout << "Insertion time: " << total_time / N << " ns" << std::endl; | ||
|
||
total_time = 0; | ||
|
||
for (size_t i = 0; i < N; ++i) | ||
{ | ||
std::string key = "key" + std::to_string(i); | ||
|
||
auto start = GetTimeStamp(); | ||
auto *value = map.Find(key); | ||
auto end = GetTimeStamp(); | ||
|
||
if (value == nullptr || *value != i) | ||
{ | ||
std::cout << "Key not found." << std::endl; | ||
} | ||
|
||
total_time += end - start; | ||
} | ||
|
||
std::cout << "Lookup time: " << total_time / N << " ns" << std::endl; | ||
|
||
delete[] buffer; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "PoolAllocator.h" | ||
#include "Timing.h" | ||
#include <iostream> | ||
|
||
void benchmark_linux_scalability() | ||
{ | ||
const size_t N = 10000000; | ||
const size_t CAPACITY = 2 * N; | ||
|
||
char *buffer = new char[PoolAllocator::CalculateMetadataBufferSize(CAPACITY)]; | ||
|
||
auto allocator = PoolAllocator::Create(buffer, CAPACITY); | ||
|
||
auto *handles = new PoolAllocator::BlockHandle[N]; | ||
|
||
auto start = GetTimeStamp(); | ||
|
||
for (size_t i = 0; i < N; ++i) | ||
{ | ||
handles[i] = allocator->Allocate(); | ||
} | ||
|
||
for (size_t i = 0; i < N; ++i) | ||
{ | ||
allocator->Deallocate(handles[i]); | ||
} | ||
|
||
auto end = GetTimeStamp(); | ||
|
||
std::cout << "Linux Scalability:" << std::endl; | ||
std::cout << "Time: " << (end - start) / 1e9 << " sec" << std::endl; | ||
std::cout << "Throughput: " << 2 * N / ((end - start) / 1e9) << " ops/s" << std::endl; | ||
std::cout << "Time per operation: " << (end - start) / (2 * N) << " ns" << std::endl; | ||
|
||
delete[] handles; | ||
delete[] buffer; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
benchmark_linux_scalability(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.