Browse Source

[multiple] perf: power-2 alloc large headers

allocate large headers by power-2 as headers to backend is generated
(mod_proxy, mod_fastcgi, mod_scgi)
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
7e8beee577
  1. 6
      src/mod_fastcgi.c
  2. 6
      src/mod_proxy.c
  3. 6
      src/mod_scgi.c

6
src/mod_fastcgi.c

@ -118,7 +118,11 @@ static int fcgi_env_add(void *venv, const char *key, size_t key_len, const char
force_assert(key_len < 0x7fffffffu);
force_assert(val_len < 0x7fffffffu);
buffer_string_prepare_append(env, len);
if (buffer_string_space(env) < len) {
size_t extend = env->size * 2 - buffer_string_length(env);
extend = extend > len ? extend : len + 4095;
buffer_string_prepare_append(env, extend);
}
if (key_len > 127) {
len_enc[len_enc_len++] = ((key_len >> 24) & 0xff) | 0x80;

6
src/mod_proxy.c

@ -792,6 +792,12 @@ static handler_t proxy_create_env(server *srv, gw_handler_ctx *gwhctx) {
vlen = buffer_string_length(ds->value);
if (0 == vlen) continue;
if (buffer_string_space(b) < klen + vlen + 4) {
size_t extend = b->size * 2 - buffer_string_length(b);
extend = extend > klen + vlen + 4 ? extend : klen + vlen + 4 + 4095;
buffer_string_prepare_append(b, extend);
}
buffer_append_string_len(b, ds->key->ptr, klen);
buffer_append_string_len(b, CONST_STR_LEN(": "));
buffer_append_string_len(b, ds->value->ptr, vlen);

6
src/mod_scgi.c

@ -100,7 +100,11 @@ static int scgi_env_add_scgi(void *venv, const char *key, size_t key_len, const
len = key_len + val_len + 2;
buffer_string_prepare_append(env, len);
if (buffer_string_space(env) < len) {
size_t extend = env->size * 2 - buffer_string_length(env);
extend = extend > len ? extend : len + 4095;
buffer_string_prepare_append(env, extend);
}
buffer_append_string_len(env, key, key_len);
buffer_append_string_len(env, "", 1);

Loading…
Cancel
Save