Skip to content

Commit 151dcb0

Browse files
committed
Update http/s3 perf
1 parent 789ad44 commit 151dcb0

2 files changed

Lines changed: 82 additions & 42 deletions

File tree

‎src/perf/fiber-http.cpp‎

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <Poco/Net/StreamSocket.h>
99

1010
#include <cerrno>
11+
#include <format>
1112

1213
#include <poll.h>
1314
#include <unistd.h>
@@ -128,7 +129,8 @@ bool FiberSocketImpl::poll(const Poco::Timespan & timeout, int mode)
128129

129130
int FiberSocketImpl::sendBytes(const void * buffer, int length, int flags)
130131
{
131-
UNUSED(flags);
132+
// Poco flags (MSG_NOSIGNAL, MSG_PEEK, etc.) are not plumbed through to io_uring read/write.
133+
ASSERT(flags == 0, "FiberSocketImpl::sendBytes does not support flags (got {})", flags);
132134

133135
int total = 0;
134136
const char * ptr = static_cast<const char *>(buffer);
@@ -165,27 +167,44 @@ int FiberSocketImpl::sendBytes(const void * buffer, int length, int flags)
165167
return total;
166168
}
167169

168-
void FiberSocketImpl::shutdown()
170+
int FiberSocketImpl::receiveBytes(void * buffer, int length, int flags)
169171
{
170-
int fd = atomicFd.load(std::memory_order_relaxed);
171-
if (fd < 0)
172+
// Poco flags (MSG_NOSIGNAL, MSG_PEEK, etc.) are not plumbed through to io_uring read/write.
173+
ASSERT(flags == 0, "FiberSocketImpl::receiveBytes does not support flags (got {})", flags);
174+
175+
#if defined(USE_IO_URING_RW)
176+
uint64_t bytesRead = 0;
177+
int r = silk::FiberScheduler::read(sockfd(), buffer, static_cast<uint64_t>(length), 0, &bytesRead);
178+
if (r)
172179
{
173-
return;
180+
error(r, "recv");
174181
}
175-
176-
int r = ::shutdown(fd, SHUT_RDWR);
177-
if (r < 0)
182+
return static_cast<int>(bytesRead);
183+
#else
184+
for (;;)
178185
{
179-
r = errno;
180-
error(r, "shutdown");
186+
ssize_t count = ::recv(sockfd(), buffer, static_cast<size_t>(length), 0);
187+
if (count >= 0)
188+
{
189+
return static_cast<int>(count);
190+
}
191+
int r = errno;
192+
if (r == EAGAIN)
193+
{
194+
r = silk::FiberScheduler::poll(sockfd(), POLLIN);
195+
if (!r)
196+
{
197+
continue;
198+
}
199+
}
200+
error(r, "recv");
181201
}
202+
#endif
182203
}
183204

184205
Poco::Net::SocketImpl * FiberServerSocketImpl::acceptConnection(Poco::Net::SocketAddress & clientAddr)
185206
{
186-
silk::FiberScheduler::IoFuture pollFuture;
187-
silk::FiberScheduler::poll(sockfd(), POLLIN, nullptr, &pollFuture);
188-
int r = pollFuture.wait();
207+
int r = silk::FiberScheduler::poll(sockfd(), POLLIN);
189208
if (r)
190209
{
191210
error(r, "accept poll");
@@ -204,36 +223,18 @@ Poco::Net::SocketImpl * FiberServerSocketImpl::acceptConnection(Poco::Net::Socke
204223
return new FiberSocketImpl(fd);
205224
}
206225

207-
int FiberSocketImpl::receiveBytes(void * buffer, int length, int flags)
226+
void FiberSocketImpl::shutdown()
208227
{
209-
UNUSED(flags);
210-
211-
#if defined(USE_IO_URING_RW)
212-
uint64_t bytesRead = 0;
213-
int r = silk::FiberScheduler::read(sockfd(), buffer, static_cast<uint64_t>(length), 0, &bytesRead);
214-
if (r)
228+
int fd = atomicFd.load(std::memory_order_relaxed);
229+
if (fd < 0)
215230
{
216-
error(r, "recv");
231+
return;
217232
}
218-
return static_cast<int>(bytesRead);
219-
#else
220-
for (;;)
233+
234+
int r = ::shutdown(fd, SHUT_RDWR);
235+
if (r < 0)
221236
{
222-
ssize_t count = ::recv(sockfd(), buffer, static_cast<size_t>(length), 0);
223-
if (count >= 0)
224-
{
225-
return static_cast<int>(count);
226-
}
227-
int r = errno;
228-
if (r == EAGAIN)
229-
{
230-
r = silk::FiberScheduler::poll(sockfd(), POLLIN);
231-
if (!r)
232-
{
233-
continue;
234-
}
235-
}
236-
error(r, "recv");
237+
r = errno;
238+
error(r, "shutdown");
237239
}
238-
#endif
239240
}

‎src/perf/s3-perf.cpp‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <aws/core/Aws.h>
1919
#include <aws/core/auth/AWSCredentials.h>
2020
#include <aws/core/client/ClientConfiguration.h>
21+
#include <aws/core/client/DefaultRetryStrategy.h>
2122
#include <aws/core/http/HttpClient.h>
2223
#include <aws/core/http/HttpClientFactory.h>
2324
#include <aws/core/http/HttpRequest.h>
@@ -183,12 +184,16 @@ makeS3Client(const ClientConfig & cfg, std::shared_ptr<Aws::Utils::Threading::Ex
183184
s3Config.useVirtualAddressing = false;
184185
s3Config.payloadSigningPolicy = Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never;
185186
s3Config.executor = std::move(executor);
187+
// The bench measures single-attempt latency. With retries enabled the SDK
188+
// would re-read slot.body on retry, which conflicts with the slot's reuse
189+
// across iterations and would muddy the latency distribution.
190+
s3Config.retryStrategy = std::make_shared<Aws::Client::DefaultRetryStrategy>(0L, 0L);
186191

187192
return std::make_unique<Aws::S3::S3Client>(
188193
creds, std::make_shared<CachingS3EndpointProvider>(cfg.endpointUrl + "/" + cfg.bucket), s3Config);
189194
}
190195

191-
static void printJson(std::vector<uint64_t> & latNs, const ClientConfig & cfg)
196+
static void printJson(std::vector<uint64_t> & latNs, const ClientConfig & cfg, uint32_t failedSessions)
192197
{
193198
uint64_t total = latNs.size();
194199
double durationS = static_cast<double>(cfg.durationNs) / 1e9;
@@ -206,6 +211,7 @@ static void printJson(std::vector<uint64_t> & latNs, const ClientConfig & cfg)
206211
printf(" \"duration_s\": %.3f,\n", durationS);
207212
printf(" \"total\": %lu,\n", total);
208213
printf(" \"rps\": %.1f,\n", opsPerSec);
214+
printf(" \"errors\": %u,\n", failedSessions);
209215
printLatencyUs(latNs);
210216
printCounters();
211217
printf("}\n");
@@ -463,6 +469,12 @@ class FiberHttpClientFactory final : public PocoHttpClientFactory
463469

464470
/**
465471
* FiberExecutor - runs SDK async tasks as fibers instead of OS threads.
472+
*
473+
* Note: SubmitToThread is unbounded -- FiberScheduler::run always succeeds, so
474+
* unlike PooledThreadExecutor (which blocks when the pool saturates) this
475+
* executor offers no backpressure. The s3-perf bench is bounded externally by
476+
* numJobs * ioDepth, so this is harmless here. Code copying this class into
477+
* production should add a bound (counting semaphore, slot accounting, etc.).
466478
*/
467479
class FiberExecutor final : public Aws::Utils::Threading::Executor
468480
{
@@ -518,6 +530,8 @@ class S3Bench
518530

519531
std::vector<uint64_t> collectLatencies();
520532

533+
uint32_t failedSessions() const;
534+
521535
private:
522536
struct Slot
523537
{
@@ -531,6 +545,7 @@ class S3Bench
531545
{
532546
std::thread thread;
533547
std::vector<uint64_t> latencies;
548+
bool failed = false;
534549
};
535550

536551
void submit(Slot & slot, uint32_t & count);
@@ -580,6 +595,19 @@ std::vector<uint64_t> S3Bench::collectLatencies()
580595
return all;
581596
}
582597

598+
uint32_t S3Bench::failedSessions() const
599+
{
600+
uint32_t count = 0;
601+
for (const Session & session : sessions)
602+
{
603+
if (session.failed)
604+
{
605+
count++;
606+
}
607+
}
608+
return count;
609+
}
610+
583611
void S3Bench::submit(Slot & slot, uint32_t & count)
584612
{
585613
bool doPut;
@@ -664,7 +692,12 @@ void S3Bench::runSession(Session * session)
664692

665693
if (slots[head].error)
666694
{
695+
// Fail-fast: a single S3 error terminates the session. With a misconfigured
696+
// endpoint or a transient failure every session exits after one bad outcome,
697+
// and the run produces no useful latency data. failedSessions exposes the
698+
// count so the caller can warn.
667699
LOG_ERROR("S3 request failed: {}", slots[head].error->GetMessage());
700+
session->failed = true;
668701
head = (head + 1) % cfg.ioDepth;
669702
break;
670703
}
@@ -802,8 +835,14 @@ int main(int argc, char ** argv)
802835
LOG_INFO("stopping benchmark");
803836
bench.stop();
804837

838+
uint32_t failedSessions = bench.failedSessions();
839+
if (failedSessions > 0)
840+
{
841+
LOG_WARN("{}/{} sessions exited early due to S3 errors", failedSessions, cfg.numJobs);
842+
}
843+
805844
auto latencies = bench.collectLatencies();
806-
printJson(latencies, cfg);
845+
printJson(latencies, cfg, failedSessions);
807846

808847
s3.reset();
809848
Aws::ShutdownAPI(sdkOptions);

0 commit comments

Comments
 (0)