Skip to content

Commit

Permalink
nghttpx: Use std::priority_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Jan 21, 2019
1 parent 8d84270 commit 8dc2b26
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 314 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ if(ENABLE_APP)
memchunk_test.cc
template_test.cc
base64_test.cc
priority_queue_test.cc
)
add_executable(nghttpx-unittest EXCLUDE_FROM_ALL
${NGHTTPX_UNITTEST_SOURCES}
Expand Down
6 changes: 2 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ NGHTTPX_SRCS = \
shrpx_dual_dns_resolver.cc shrpx_dual_dns_resolver.h \
shrpx_dns_tracker.cc shrpx_dns_tracker.h \
buffer.h memchunk.h template.h allocator.h \
xsi_strerror.c xsi_strerror.h \
priority_queue.h
xsi_strerror.c xsi_strerror.h

if HAVE_MRUBY
NGHTTPX_SRCS += \
Expand Down Expand Up @@ -187,8 +186,7 @@ nghttpx_unittest_SOURCES = shrpx-unittest.cc \
buffer_test.cc buffer_test.h \
memchunk_test.cc memchunk_test.h \
template_test.cc template_test.h \
base64_test.cc base64_test.h \
priority_queue_test.cc priority_queue_test.h
base64_test.cc base64_test.h
nghttpx_unittest_CPPFLAGS = ${AM_CPPFLAGS} \
-DNGHTTP2_SRC_DIR=\"$(top_srcdir)/src\"
nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} @CUNIT_LIBS@ @TESTLDADD@
Expand Down
145 changes: 0 additions & 145 deletions src/priority_queue.h

This file was deleted.

93 changes: 0 additions & 93 deletions src/priority_queue_test.cc

This file was deleted.

38 changes: 0 additions & 38 deletions src/priority_queue_test.h

This file was deleted.

5 changes: 1 addition & 4 deletions src/shrpx-unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "shrpx_config.h"
#include "tls.h"
#include "shrpx_router_test.h"
#include "priority_queue_test.h"
#include "shrpx_log.h"

static int init_suite1(void) { return 0; }
Expand Down Expand Up @@ -218,9 +217,7 @@ int main(int argc, char *argv[]) {
!CU_add_test(pSuite, "template_string_ref",
nghttp2::test_template_string_ref) ||
!CU_add_test(pSuite, "base64_encode", nghttp2::test_base64_encode) ||
!CU_add_test(pSuite, "base64_decode", nghttp2::test_base64_decode) ||
!CU_add_test(pSuite, "priority_queue_push",
nghttp2::test_priority_queue_push)) {
!CU_add_test(pSuite, "base64_decode", nghttp2::test_base64_decode)) {
CU_cleanup_registry();
return CU_get_error();
}
Expand Down
18 changes: 10 additions & 8 deletions src/shrpx_client_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -754,27 +754,29 @@ uint32_t ClientHandler::get_affinity_cookie(Downstream *downstream,
}

namespace {
void reschedule_addr(PriorityQueue<DownstreamAddrKey, DownstreamAddr *,
DownstreamAddrKeyLess> &pq,
DownstreamAddr *addr) {
void reschedule_addr(
std::priority_queue<DownstreamAddrEntry, std::vector<DownstreamAddrEntry>,
DownstreamAddrEntryGreater> &pq,
DownstreamAddr *addr) {
auto penalty = MAX_DOWNSTREAM_ADDR_WEIGHT + addr->pending_penalty;
addr->cycle += penalty / addr->weight;
addr->pending_penalty = penalty % addr->weight;

pq.emplace(DownstreamAddrKey{addr->cycle, addr->seq}, addr);
pq.push(DownstreamAddrEntry{addr, addr->seq, addr->cycle});
addr->queued = true;
}
} // namespace

namespace {
void reschedule_wg(
PriorityQueue<DownstreamAddrKey, WeightGroup *, DownstreamAddrKeyLess> &pq,
std::priority_queue<WeightGroupEntry, std::vector<WeightGroupEntry>,
WeightGroupEntryGreater> &pq,
WeightGroup *wg) {
auto penalty = MAX_DOWNSTREAM_ADDR_WEIGHT + wg->pending_penalty;
wg->cycle += penalty / wg->weight;
wg->pending_penalty = penalty % wg->weight;

pq.emplace(DownstreamAddrKey{wg->cycle, wg->seq}, wg);
pq.push(WeightGroupEntry{wg, wg->seq, wg->cycle});
wg->queued = true;
}
} // namespace
Expand Down Expand Up @@ -857,7 +859,7 @@ DownstreamAddr *ClientHandler::get_downstream_addr(int &err,
return nullptr;
}

auto wg = wgpq.top();
auto wg = wgpq.top().wg;
wgpq.pop();
wg->queued = false;

Expand All @@ -866,7 +868,7 @@ DownstreamAddr *ClientHandler::get_downstream_addr(int &err,
break;
}

auto addr = wg->pq.top();
auto addr = wg->pq.top().addr;
wg->pq.pop();
addr->queued = false;

Expand Down
Loading

0 comments on commit 8dc2b26

Please sign in to comment.