Skip to content

Commit

Permalink
Lwan: Update benchmark_config.json to point to the correct config (Te…
Browse files Browse the repository at this point in the history
…chEmpower#5848)

* Lwan: Avoid indirect memory allocation while fetching cached queries

* Lwan: Cached queries benchmark uses "cached_query_url" in config.json
  • Loading branch information
lpereira authored Jul 7, 2020
1 parent e2382db commit 5126e18
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frameworks/C/lwan/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"json_url": "/json",
"db_url": "/db",
"query_url": "/queries?queries=",
"cached_worlds_url": "/cached-worlds?count=",
"cached_query_url": "/cached-queries?count=",
"plaintext_url": "/plaintext",
"fortune_url": "/fortunes",
"port": 8080,
Expand Down
35 changes: 33 additions & 2 deletions frameworks/C/lwan/src/techempower.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,36 @@ static void cached_queries_free(struct cache_entry *entry, void *context)
free(entry);
}

LWAN_HANDLER(cached_worlds)
static struct cache_entry *my_cache_coro_get_and_ref_entry(struct cache *cache,
struct coro *coro,
const char *key)
{
/* Using this function instead of cache_coro_get_and_ref_entry() will avoid
* calling coro_defer(), which, in cases where the number of cached queries is
* too high, will trigger reallocations of the coro_defer array (and the "demotion"
* from the storage inlined in the coro struct to somewhere in the heap).
*
* For large number of cached elements, too, this will reduce the number of
* indirect calls that are performed every time a request is serviced.
*/

for (int tries = 16; tries; tries--) {
int error;
struct cache_entry *ce = cache_get_and_ref_entry(cache, key, &error);

if (LIKELY(ce))
return ce;

if (error != EWOULDBLOCK)
break;

coro_yield(coro, CONN_CORO_YIELD);
}

return NULL;
}

LWAN_HANDLER(cached_queries)
{
const char *queries_str = lwan_request_get_query_param(request, "count");
long queries;
Expand All @@ -319,13 +348,15 @@ LWAN_HANDLER(cached_worlds)
struct db_json_cached *jc;
size_t discard;

jc = (struct db_json_cached *)cache_coro_get_and_ref_entry(
jc = (struct db_json_cached *)my_cache_coro_get_and_ref_entry(
cached_queries_cache, request->conn->coro,
int_to_string(rand() % 10000, key_buf, &discard));
if (UNLIKELY(!jc))
return HTTP_INTERNAL_ERROR;

qj.queries[i] = jc->db_json;

cache_entry_unref(cached_queries_cache, (struct cache_entry *)jc);
}

/* Avoid reallocations/copies while building response. Each response
Expand Down
2 changes: 1 addition & 1 deletion frameworks/C/lwan/techempower.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ listener *:8080 {
&json /json
&db /db
&queries /queries
&cached_worlds /cached-worlds
&cached_queries /cached-queries
&fortunes /fortunes

# For Lua version of TWFB benchmarks
Expand Down

0 comments on commit 5126e18

Please sign in to comment.