v1.0.0-rc.127 (#34)
All checks were successful
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 10m51s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 8m0s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 9m6s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 10m7s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 9m47s
Build Packages / Generate python client (push) Successful in 29s
Build Packages / Build documentation (push) Successful in 43s
Build Packages / Create release (push) Has been skipped
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 10m46s
Build Packages / build:rpm (rocky8) (push) Successful in 9m33s
Build Packages / Unit tests (push) Has been skipped
Build Packages / build:rpm (ubuntu2204) (push) Successful in 8m47s
Build Packages / build:rpm (rocky9) (push) Successful in 9m55s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 9m4s

This is an UNSTABLE release. The release has significant modifications and bug fixes, if things go wrong, it is better to revert to 1.0.0-rc.124.

* jfjoch_broker: Default EIGER readout time is 20 microseconds
* jfjoch_broker: Multiple improvements regarding performance
* jfjoch_broker: Image buffer allows to track frames in preparation and sending
* jfjoch_broker: Dedicated thread for ZeroMQ transmission to better utilize the image buffer
* jfjoch_broker: Experimental implementation of transmission with raw TCP/IP sockets
* jfjoch_writer: Fixes regarding properly closing files in long data collections
* jfjoch_process: Scale & merge has been significantly improved, but it is not yet integrated into mainstream code

Reviewed-on: #34
This commit was merged in pull request #34.
This commit is contained in:
2026-03-02 15:57:12 +01:00
parent 32b681e591
commit f3e0a15d26
205 changed files with 2685 additions and 1046 deletions

View File

@@ -4,6 +4,7 @@
#include "ImageBuffer.h"
#include "JFJochException.h"
#include "ZeroCopyReturnValue.h"
#ifdef JFJOCH_USE_NUMA
#include <numa.h>
@@ -15,15 +16,18 @@ ImageBuffer::ImageBuffer(size_t buffer_size_bytes)
: buffer_size(buffer_size_bytes) {
#ifdef JFJOCH_USE_NUMA
buffer = (uint8_t *) numa_alloc_interleaved(buffer_size);
#else
buffer = (uint8_t *) mmap (nullptr, buffer_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) ;
#endif
buffer = static_cast<uint8_t *>(numa_alloc_interleaved(buffer_size));
if (buffer == nullptr)
throw JFJochException(JFJochExceptionCategory::MemAllocFailed,
"Failed to allocate image buffer");
#else
buffer = (uint8_t *) mmap (nullptr, buffer_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) ;
if (buffer == MAP_FAILED)
throw JFJochException(JFJochExceptionCategory::MemAllocFailed,
"Failed to allocate image buffer");
#endif
memset(buffer, 0, buffer_size);
}
@@ -55,8 +59,10 @@ void ImageBuffer::StartMeasurement(size_t in_location_size) {
// Ensure that requests are allowed and clear active process counters
disable_requests = false;
zeromq_in_process = 0;
preview_in_process = 0;
slots_sending = 0;
slots_preparation = 0;
slots_in_preview = 0;
slots_idle = 0;
// Clear queue and vectors
while (!free_slots.empty())
@@ -81,11 +87,19 @@ void ImageBuffer::StartMeasurement(const DiffractionExperiment &experiment) {
bool ImageBuffer::CheckIfBufferReturned(std::chrono::microseconds timeout) {
std::unique_lock ul(m);
if (zeromq_in_process > 0)
cv_zeromq_done.wait_for(ul, timeout, [this] {
return zeromq_in_process == 0;
auto time_point = std::chrono::steady_clock::now() + timeout;
if (slots_preparation > 0)
cv_preparation_done.wait_until(ul, time_point, [this] {
return slots_preparation == 0;
});
return zeromq_in_process == 0;
if (slots_sending > 0)
cv_send_done.wait_until(ul, time_point, [this] {
return slots_sending == 0;
});
return (slots_preparation == 0) && (slots_sending == 0);
}
ZeroCopyReturnValue *ImageBuffer::GetImageSlot() {
@@ -95,15 +109,13 @@ ZeroCopyReturnValue *ImageBuffer::GetImageSlot() {
auto i = free_slots.front();
free_slots.pop();
// Wait for already existing preview threads and don't allow new ones
v[i].zeromq_processing = true;
// Clear image number/size
v[i].status = ImageBufferEntryStatus::InPreparation;
v[i].image_number = INT64_MIN;
v[i].image_size = 0;
v[i].indexed = false;
++zeromq_in_process;
--slots_idle;
++slots_preparation;
// Wait for any preview thread currently reading this one
// All has to be ready, as waiting on cv_preview_done will release mutex
@@ -117,20 +129,55 @@ ZeroCopyReturnValue *ImageBuffer::GetImageSlot() {
int64_t ImageBuffer::GetAvailSlots() const {
std::unique_lock ul(m);
return slot_count - zeromq_in_process;
return slot_count - slots_preparation - slots_sending;
}
void ImageBuffer::ReleaseSlot(uint32_t location, int64_t image_number, size_t image_size, bool indexed) {
void ImageBuffer::ReadyToSend(uint32_t location, int64_t image_number, size_t image_size, bool indexed) {
std::unique_lock ul(m);
// Technically below should cause an exception,
// but this will run in a multithreaded context,
// where exceptions might not be caught,
// so for now - just ignore
if (location >= v.size())
return;
if (v[location].status != ImageBufferEntryStatus::InPreparation)
return;
++counter;
zeromq_in_process--;
v[location].zeromq_processing = false;
++slots_sending;
--slots_preparation;
v[location].status = ImageBufferEntryStatus::Sending;
v[location].image_number = image_number;
v[location].image_size = image_size;
v[location].indexed = indexed;
free_slots.push(location);
cv_zeromq_done.notify_all();
cv_preparation_done.notify_all();
}
void ImageBuffer::ReleaseSlot(uint32_t location) {
std::unique_lock ul(m);
// Technically below should cause an exception,
// but this will run in a multithreaded context,
// where exceptions might not be caught,
// so for now - just ignore
if (location >= v.size())
return;
if (v[location].status != ImageBufferEntryStatus::Sending)
return;
++slots_idle;
--slots_sending;
v[location].status = ImageBufferEntryStatus::Idle;
free_slots.push(location);
cv_send_done.notify_all();
}
bool ImageBuffer::Finalize(std::chrono::microseconds timeout) {
@@ -159,19 +206,22 @@ bool ImageBuffer::GetImage(std::vector<uint8_t> &out_v, int64_t image_number) {
uint32_t i = val.value();
if (v[i].zeromq_processing)
if (v[i].status == ImageBufferEntryStatus::InPreparation
|| v[i].status == ImageBufferEntryStatus::Empty)
return false;
// Unlock mutex to allow memory copy happen outside the critical section
++preview_in_process;
// Unlock mutex to allow memory copy to happen outside the critical section
++slots_in_preview;
++v[i].readers;
size_t image_size = v[i].image_size;
ul.unlock();
out_v.resize(v[i].image_size);
memcpy(out_v.data(), GetBufferLocation(i), v[i].image_size);
out_v.resize(image_size);
memcpy(out_v.data(), GetBufferLocation(i), image_size);
ul.lock();
--preview_in_process;
--slots_in_preview;
--v[i].readers;
cv_preview_done.notify_all();
return true;
@@ -179,22 +229,32 @@ bool ImageBuffer::GetImage(std::vector<uint8_t> &out_v, int64_t image_number) {
bool ImageBuffer::FinalizeInternal(std::unique_lock<std::mutex> &ul, std::chrono::microseconds timeout) {
disable_requests = true;
if (preview_in_process > 0)
cv_preview_done.wait_for(ul, timeout,
[this] {return preview_in_process == 0;}
auto time_point = std::chrono::steady_clock::now() + timeout;
if (slots_in_preview > 0)
cv_preview_done.wait_until(ul, time_point,
[this] {return slots_in_preview == 0;}
);
if (zeromq_in_process > 0)
cv_zeromq_done.wait_for(ul, timeout,
[this] {return zeromq_in_process == 0;
if (slots_preparation > 0)
cv_preparation_done.wait_until(ul, time_point,
[this] {return slots_preparation == 0;}
);
if (slots_sending > 0)
cv_send_done.wait_until(ul, time_point,
[this] {return slots_sending == 0;
});
++counter;
return (preview_in_process == 0) && (zeromq_in_process == 0);
return (slots_preparation == 0) && (slots_in_preview == 0) && (slots_sending == 0);
}
std::optional<uint32_t> ImageBuffer::getHandle(int64_t image_number) const {
for (int i = 0; i < slot_count; i++) {
if (!v[i].zeromq_processing && v[i].image_number == image_number)
if (v[i].status != ImageBufferEntryStatus::Empty
&& v[i].status != ImageBufferEntryStatus::InPreparation
&& v[i].image_number == image_number)
return i;
}
return {};
@@ -205,7 +265,10 @@ std::optional<uint32_t> ImageBuffer::getHandleMaxImage() const {
std::optional<uint32_t> ret;
for (int i = 0; i < slot_count; i++) {
// if this is never true, then optional will remain empty
if (!v[i].zeromq_processing && v[i].image_number > max_image_number && v[i].image_number >= 0) {
if (v[i].status != ImageBufferEntryStatus::Empty
&& v[i].status != ImageBufferEntryStatus::InPreparation
&& v[i].image_number > max_image_number
&& v[i].image_number >= 0) {
max_image_number = v[i].image_number;
ret = i;
}
@@ -218,7 +281,11 @@ std::optional<uint32_t> ImageBuffer::getHandleMaxIndexedImage() const {
std::optional<uint32_t> ret;
for (int i = 0; i < slot_count; i++) {
// if this is never true, then optional will remain empty
if (!v[i].zeromq_processing && v[i].image_number > max_image_number && v[i].image_number >= 0 && v[i].indexed) {
if (v[i].status != ImageBufferEntryStatus::Empty
&& v[i].status != ImageBufferEntryStatus::InPreparation
&& v[i].image_number > max_image_number
&& v[i].image_number >= 0
&& v[i].indexed) {
max_image_number = v[i].image_number;
ret = i;
}
@@ -241,6 +308,7 @@ void ImageBuffer::GetStartMessage(std::vector<uint8_t> &out_v) {
}
void ImageBuffer::SaveStartMessage(const std::vector<uint8_t> &msg) {
std::unique_lock ul(start_message_mutex);
start_message = msg;
}
@@ -249,7 +317,9 @@ ImageBufferStatus ImageBuffer::GetStatus() const {
{
std::unique_lock ul(m);
ret.total_slots = slot_count;
ret.available_slots = slot_count - zeromq_in_process;
ret.available_slots = slot_count - slots_sending - slots_preparation;
ret.preparation_slots = slots_preparation;
ret.sending_slots = slots_sending;
ret.min_image_number = INT64_MAX;
ret.max_image_number = 0;