Skip to content

Commit 4f7538d

Browse files
Bin Liufacebook-github-bot
Bin Liu
authored andcommitted
exclude timeout and oom kills when measuring goodput
Reviewed By: jtwarren Differential Revision: D71139470 fbshipit-source-id: 490efff7ce83b238de3f2bbe69c85ba405b0e0f1
1 parent b016c2b commit 4f7538d

5 files changed

+38
-11
lines changed

hphp/runtime/base/execution-context-inl.h

+16
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,22 @@ inline void ExecutionContext::setSandboxId(const String& sandboxId) {
212212
m_sandboxId = sandboxId;
213213
}
214214

215+
inline void ExecutionContext::markTimedOut() {
216+
m_timedOut = true;
217+
}
218+
219+
inline bool ExecutionContext::isTimedOut() const {
220+
return m_timedOut;
221+
}
222+
223+
inline void ExecutionContext::markOOMKilled() {
224+
m_killed = true;
225+
}
226+
227+
inline bool ExecutionContext::isOOMKilled() const {
228+
return m_killed;
229+
}
230+
215231
inline bool ExecutionContext::hasRequestEventHandlers() const {
216232
return !m_requestEventHandlers.empty();
217233
}

hphp/runtime/base/execution-context.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ void ExecutionContext::onShutdownPostSend() {
714714
executeFunctions(PostSend);
715715
} catch (...) {
716716
try {
717-
bump_counter_and_rethrow(true /* isPsp */);
717+
bump_counter_and_rethrow(true /* isPsp */, this);
718718
} catch (const ExitException&) {
719719
// do nothing
720720
} catch (const Exception& e) {
@@ -734,8 +734,8 @@ void ExecutionContext::onShutdownPostSend() {
734734
// error handling
735735

736736
bool ExecutionContext::errorNeedsHandling(int errnum,
737-
bool callUserHandler,
738-
ErrorThrowMode mode) {
737+
bool callUserHandler,
738+
ErrorThrowMode mode) {
739739
if (UNLIKELY(m_throwAllErrors)) {
740740
throw Exception(folly::sformat("throwAllErrors: {}", errnum));
741741
}
@@ -914,15 +914,15 @@ bool ExecutionContext::callUserErrorHandler(const Exception& e, int errnum,
914914
{ServiceData::StatsType::COUNT});
915915
requestErrorHandlerTimeoutCounter->addValue(1);
916916
ServerStats::Log("request.timed_out.error_handler", 1);
917-
917+
markTimedOut();
918918
if (!swallowExceptions) throw;
919919
} catch (const RequestCPUTimeoutException&) {
920920
static auto requestErrorHandlerCPUTimeoutCounter =
921921
ServiceData::createTimeSeries("requests_cpu_timed_out_error_handler",
922922
{ServiceData::StatsType::COUNT});
923923
requestErrorHandlerCPUTimeoutCounter->addValue(1);
924924
ServerStats::Log("request.cpu_timed_out.error_handler", 1);
925-
925+
markTimedOut();
926926
if (!swallowExceptions) throw;
927927
} catch (const RequestMemoryExceededException&) {
928928
static auto requestErrorHandlerMemoryExceededCounter =

hphp/runtime/base/execution-context.h

+10
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ struct ExecutionContext {
349349
// options.
350350
void onLoadWithOptions(const char* f, const RepoOptions& options);
351351

352+
// Check if request timed out (e.g., due to overload)
353+
void markTimedOut();
354+
bool isTimedOut() const;
355+
356+
// Check if request got killed by the request OOM killer.
357+
void markOOMKilled();
358+
bool isOOMKilled() const;
359+
352360
private:
353361
struct OutputBuffer {
354362
explicit OutputBuffer(Variant&& h, int chunk_sz, OBFlags flgs)
@@ -561,6 +569,8 @@ struct ExecutionContext {
561569
req::list<OutputBuffer> m_buffers; // a stack of output buffers
562570
bool m_insideOBHandler{false};
563571
bool m_implicitFlush;
572+
bool m_timedOut{false};
573+
bool m_killed{false};
564574
int m_protectedLevel;
565575

566576
// Debugger stdout hook is treated differently. If it is non-null,

hphp/runtime/base/program-functions.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static void handle_exception_append_bt(std::string& errorMsg,
474474
}
475475
}
476476

477-
void bump_counter_and_rethrow(bool isPsp) {
477+
void bump_counter_and_rethrow(bool isPsp, ExecutionContext* context) {
478478
try {
479479
throw;
480480
} catch (const RequestTimeoutException&) {
@@ -489,6 +489,7 @@ void bump_counter_and_rethrow(bool isPsp) {
489489
requestTimeoutCounter->addValue(1);
490490
ServerStats::Log("request.timed_out.non_psp", 1);
491491
}
492+
context->markTimedOut();
492493
throw;
493494
} catch (const RequestCPUTimeoutException&) {
494495
if (isPsp) {
@@ -502,6 +503,7 @@ void bump_counter_and_rethrow(bool isPsp) {
502503
requestCPUTimeoutCounter->addValue(1);
503504
ServerStats::Log("request.cpu_timed_out.non_psp", 1);
504505
}
506+
context->markTimedOut();
505507
throw;
506508
} catch (const RequestMemoryExceededException&) {
507509
if (isPsp) {
@@ -533,11 +535,10 @@ void bump_counter_and_rethrow(bool isPsp) {
533535
StructuredLogEntry entry;
534536
entry.setInt("mem_used", e.m_usedBytes);
535537
entry.setInt("is_psp", static_cast<int>(isPsp));
536-
if (g_context) {
537-
entry.setStr("url", g_context->getRequestUrl());
538-
}
538+
entry.setStr("url", context->getRequestUrl());
539539
StructuredLog::log("hhvm_oom_killed", entry);
540540
}
541+
context->markOOMKilled();
541542
throw;
542543
}
543544
}
@@ -557,7 +558,7 @@ static void handle_exception_helper(bool& ret,
557558
};
558559

559560
try {
560-
bump_counter_and_rethrow(false /* isPsp */);
561+
bump_counter_and_rethrow(false /* isPsp */, context);
561562
} catch (const Eval::DebuggerException&) {
562563
throw;
563564
} catch (const ExitException& e) {

hphp/runtime/base/program-functions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ bool is_hphp_session_initialized();
128128
std::string get_embedded_section(const std::string& section_name);
129129

130130
// Helper function for stats tracking with exceptions.
131-
void bump_counter_and_rethrow(bool isPsp);
131+
void bump_counter_and_rethrow(bool isPsp, ExecutionContext* context);
132132

133133
std::vector<int> get_executable_lines(const Unit*);
134134

0 commit comments

Comments
 (0)