generated from mochi-hpc/thallium-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* trying out external progress ULT for kafka producer * slight fix in kafka progress loop * fixed flushing of batches * working on de-batching the KafkaProducer * fixed producer * fixed producer (again) * re-enabled batch-based producer * fixed hang in batch producer * small change to consumer
- Loading branch information
Showing
18 changed files
with
538 additions
and
115 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
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
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,81 @@ | ||
/* | ||
* (C) 2023 The University of Chicago | ||
* | ||
* See COPYRIGHT in top-level directory. | ||
*/ | ||
#include "mofka/Producer.hpp" | ||
#include "mofka/Result.hpp" | ||
#include "mofka/Exception.hpp" | ||
#include "mofka/TopicHandle.hpp" | ||
#include "mofka/Future.hpp" | ||
|
||
#include "Promise.hpp" | ||
#include "KafkaBatchProducer.hpp" | ||
#include "ActiveProducerBatchQueue.hpp" | ||
#include "PimplUtil.hpp" | ||
#include <limits> | ||
|
||
#include <thallium/serialization/stl/string.hpp> | ||
#include <thallium/serialization/stl/pair.hpp> | ||
|
||
namespace mofka { | ||
|
||
KafkaBatchProducer::KafkaBatchProducer( | ||
std::string_view name, | ||
BatchSize batch_size, | ||
ThreadPool thread_pool, | ||
Ordering ordering, | ||
std::shared_ptr<KafkaTopicHandle> topic, | ||
std::shared_ptr<rd_kafka_t> kprod, | ||
std::shared_ptr<rd_kafka_topic_t> ktopic) | ||
: BatchProducer(name, batch_size, std::move(thread_pool), ordering, TopicHandle(topic)) | ||
, m_topic(std::move(topic)) | ||
, m_kafka_producer(std::move(kprod)) | ||
, m_kafka_topic(std::move(ktopic)) | ||
{ | ||
start(); | ||
} | ||
|
||
std::shared_ptr<ProducerBatchInterface> KafkaBatchProducer::newBatchForPartition(size_t index) const { | ||
if(index >= m_topic->m_partitions.size()) { | ||
throw Exception{"Invalid index returned by partition selector"}; | ||
} | ||
return std::make_shared<KafkaProducerBatch>( | ||
this, m_kafka_producer, m_kafka_topic, index); | ||
} | ||
|
||
void KafkaBatchProducer::flush() { | ||
BatchProducer::flush(); | ||
} | ||
|
||
void KafkaBatchProducer::start() { | ||
m_should_stop = false; | ||
auto run = [this](){ | ||
while(!m_should_stop) { | ||
{ | ||
std::unique_lock<tl::mutex> pending_guard{m_num_pending_batches_mtx}; | ||
m_num_pending_batches_cv.wait(pending_guard, | ||
[this](){ return m_should_stop || m_num_pending_batches > 0; }); | ||
} | ||
while(rd_kafka_poll(m_kafka_producer.get(), 0) != 0) { | ||
if(m_should_stop) break; | ||
tl::thread::yield(); | ||
} | ||
if(m_should_stop) break; | ||
tl::thread::yield(); | ||
} | ||
m_poll_ult_stopped.set_value(); | ||
}; | ||
m_thread_pool.pushWork(std::move(run)); | ||
} | ||
|
||
KafkaBatchProducer::~KafkaBatchProducer() { | ||
flush(); | ||
if(!m_should_stop) { | ||
m_should_stop = true; | ||
m_num_pending_batches_cv.notify_all(); | ||
m_poll_ult_stopped.wait(); | ||
} | ||
} | ||
|
||
} |
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,64 @@ | ||
/* | ||
* (C) 2024 The University of Chicago | ||
* | ||
* See COPYRIGHT in top-level directory. | ||
*/ | ||
#ifndef MOFKA_KAFKA_BATCH_PRODUCER_IMPL_H | ||
#define MOFKA_KAFKA_BATCH_PRODUCER_IMPL_H | ||
|
||
#include "KafkaTopicHandle.hpp" | ||
#include "KafkaPartitionInfo.hpp" | ||
#include "KafkaProducerBatch.hpp" | ||
#include "BatchProducer.hpp" | ||
|
||
#include "mofka/TopicHandle.hpp" | ||
#include "mofka/Producer.hpp" | ||
#include "mofka/UUID.hpp" | ||
#include "mofka/Ordering.hpp" | ||
|
||
#include <thallium.hpp> | ||
#include <string_view> | ||
#include <queue> | ||
|
||
#include <librdkafka/rdkafka.h> | ||
|
||
namespace mofka { | ||
|
||
namespace tl = thallium; | ||
|
||
class KafkaTopicHandle; | ||
|
||
class KafkaBatchProducer : public BatchProducer { | ||
|
||
public: | ||
|
||
std::shared_ptr<KafkaTopicHandle> m_topic; | ||
std::shared_ptr<rd_kafka_t> m_kafka_producer; | ||
std::shared_ptr<rd_kafka_topic_t> m_kafka_topic; | ||
std::atomic<bool> m_should_stop = true; | ||
tl::eventual<void> m_poll_ult_stopped; | ||
|
||
mutable size_t m_num_pending_batches = 0; | ||
mutable tl::mutex m_num_pending_batches_mtx; | ||
mutable tl::condition_variable m_num_pending_batches_cv; | ||
|
||
KafkaBatchProducer(std::string_view name, | ||
BatchSize batch_size, | ||
ThreadPool thread_pool, | ||
Ordering ordering, | ||
std::shared_ptr<KafkaTopicHandle> topic, | ||
std::shared_ptr<rd_kafka_t> kprod, | ||
std::shared_ptr<rd_kafka_topic_t> ktopic); | ||
|
||
~KafkaBatchProducer(); | ||
|
||
void flush() override; | ||
|
||
std::shared_ptr<ProducerBatchInterface> newBatchForPartition(size_t index) const override; | ||
|
||
void start(); | ||
}; | ||
|
||
} | ||
|
||
#endif |
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.