Browse Source

[core] perf: append response directly into write q

prepend non-dynamic response directly into write queue chunkqueue
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
40d3408328
  1. 14
      src/chunk.c
  2. 2
      src/chunk.h
  3. 5
      src/mod_dirlisting.c
  4. 26
      src/mod_status.c
  5. 15
      src/mod_webdav.c

14
src/chunk.c

@ -329,6 +329,20 @@ void chunkqueue_prepend_buffer_commit(chunkqueue *cq) {
}
buffer * chunkqueue_append_buffer_open(chunkqueue *cq) {
chunk *c = chunkqueue_get_unused_chunk(cq);
c->type = MEM_CHUNK;
chunkqueue_append_chunk(cq, c);
buffer_string_prepare_append(c->mem, 4095);
return c->mem;
}
void chunkqueue_append_buffer_commit(chunkqueue *cq) {
cq->bytes_in += buffer_string_length(cq->last->mem);
}
void chunkqueue_get_memory(chunkqueue *cq, char **mem, size_t *len, size_t min_size, size_t alloc_size) {
static const size_t REALLOC_MAX_SIZE = 256;
chunk *c;

2
src/chunk.h

@ -64,6 +64,8 @@ void chunkqueue_append_chunkqueue(chunkqueue *cq, chunkqueue *src);
buffer * chunkqueue_prepend_buffer_open(chunkqueue *cq);
void chunkqueue_prepend_buffer_commit(chunkqueue *cq);
buffer * chunkqueue_append_buffer_open(chunkqueue *cq);
void chunkqueue_append_buffer_commit(chunkqueue *cq);
struct server; /*(declaration)*/
int chunkqueue_append_mem_to_tempfile(struct server *srv, chunkqueue *cq, const char *mem, size_t len);

5
src/mod_dirlisting.c

@ -1052,7 +1052,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf
if (files.used) http_dirls_sort(files.ent, files.used);
out = buffer_init();
out = chunkqueue_append_buffer_open(con->write_queue);
http_list_directory_header(srv, con, p, out);
/* directories */
@ -1144,9 +1144,8 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(p->content_charset));
}
chunkqueue_append_buffer_commit(con->write_queue);
con->file_finished = 1;
chunkqueue_append_buffer(con->write_queue, out);
buffer_free(out);
return 0;
}

26
src/mod_status.c

@ -198,7 +198,7 @@ static int mod_status_get_multiplier(double *avg, char *multiplier, int size) {
static handler_t mod_status_handle_server_status_html(server *srv, connection *con, void *p_d) {
plugin_data *p = p_d;
buffer *b = buffer_init();
buffer *b = chunkqueue_append_buffer_open(con->write_queue);
size_t j;
double avg;
char multiplier = '\0';
@ -585,8 +585,7 @@ static handler_t mod_status_handle_server_status_html(server *srv, connection *c
"</html>\n"
));
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
chunkqueue_append_buffer_commit(con->write_queue);
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
@ -596,7 +595,7 @@ static handler_t mod_status_handle_server_status_html(server *srv, connection *c
static handler_t mod_status_handle_server_status_text(server *srv, connection *con, void *p_d) {
plugin_data *p = p_d;
buffer *b = buffer_init();
buffer *b = chunkqueue_append_buffer_open(con->write_queue);
double avg;
time_t ts;
char buf[32];
@ -647,8 +646,7 @@ static handler_t mod_status_handle_server_status_text(server *srv, connection *c
}
buffer_append_string_len(b, CONST_STR_LEN("\n"));
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
chunkqueue_append_buffer_commit(con->write_queue);
/* set text/plain output */
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain"));
@ -659,7 +657,7 @@ static handler_t mod_status_handle_server_status_text(server *srv, connection *c
static handler_t mod_status_handle_server_status_json(server *srv, connection *con, void *p_d) {
plugin_data *p = p_d;
buffer *b = buffer_init();
buffer *b = chunkqueue_append_buffer_open(con->write_queue);
double avg;
time_t ts;
char buf[32];
@ -732,8 +730,7 @@ static handler_t mod_status_handle_server_status_json(server *srv, connection *c
if (jsonp) buffer_append_string_len(b, CONST_STR_LEN(");"));
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
chunkqueue_append_buffer_commit(con->write_queue);
/* set text/plain output */
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("application/javascript"));
@ -756,7 +753,7 @@ static handler_t mod_status_handle_server_statistics(server *srv, connection *co
return HANDLER_FINISHED;
}
b = buffer_init();
b = chunkqueue_append_buffer_open(con->write_queue);
for (i = 0; i < st->used; i++) {
size_t ndx = st->sorted[i];
@ -765,9 +762,7 @@ static handler_t mod_status_handle_server_statistics(server *srv, connection *co
buffer_append_int(b, ((data_integer *)(st->data[ndx]))->value);
buffer_append_string_len(b, CONST_STR_LEN("\n"));
}
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
chunkqueue_append_buffer_commit(con->write_queue);
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain"));
@ -798,7 +793,7 @@ static handler_t mod_status_handle_server_status(server *srv, connection *con, v
static handler_t mod_status_handle_server_config(server *srv, connection *con, void *p_d) {
plugin_data *p = p_d;
buffer *b = buffer_init();
buffer *b = chunkqueue_append_buffer_open(con->write_queue);
buffer *m = p->module_list;
size_t i;
@ -851,8 +846,7 @@ static handler_t mod_status_handle_server_config(server *srv, connection *con, v
"</html>\n"
));
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
chunkqueue_append_buffer_commit(con->write_queue);
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));

15
src/mod_webdav.c

@ -1213,7 +1213,7 @@ static int webdav_parse_chunkqueue(server *srv, connection *con, handler_ctx *hc
#ifdef USE_LOCKS
static int webdav_lockdiscovery(connection *con, buffer *locktoken, const char *lockscope, const char *locktype, int depth) {
buffer *b = buffer_init();
buffer *b = chunkqueue_append_buffer_open(con->write_queue);
http_header_response_set(con, HTTP_HEADER_OTHER, CONST_STR_LEN("Lock-Token"), CONST_BUF_LEN(locktoken));
@ -1229,8 +1229,7 @@ static int webdav_lockdiscovery(connection *con, buffer *locktoken, const char *
buffer_append_string_len(b,CONST_STR_LEN("</D:lockdiscovery>\n"));
buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
chunkqueue_append_buffer_commit(con->write_queue);
return 0;
}
@ -1452,7 +1451,7 @@ SUBREQUEST_FUNC(mod_webdav_subrequest_handler_huge) {
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/xml; charset=\"utf-8\""));
b = buffer_init();
b = chunkqueue_append_buffer_open(con->write_queue);
buffer_copy_string_len(b, CONST_STR_LEN("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"));
@ -1599,8 +1598,7 @@ SUBREQUEST_FUNC(mod_webdav_subrequest_handler_huge) {
log_error_write(srv, __FILE__, __LINE__, "sb", "XML-response-body:", b);
}
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
chunkqueue_append_buffer_commit(con->write_queue);
con->file_finished = 1;
@ -1677,7 +1675,7 @@ SUBREQUEST_FUNC(mod_webdav_subrequest_handler_huge) {
/* we got an error somewhere in between, build a 207 */
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/xml; charset=\"utf-8\""));
b = buffer_init();
b = chunkqueue_append_buffer_open(con->write_queue);
buffer_copy_string_len(b, CONST_STR_LEN("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"));
@ -1691,8 +1689,7 @@ SUBREQUEST_FUNC(mod_webdav_subrequest_handler_huge) {
log_error_write(srv, __FILE__, __LINE__, "sb", "XML-response-body:", b);
}
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
chunkqueue_append_buffer_commit(con->write_queue);
con->http_status = 207;
con->file_finished = 1;

Loading…
Cancel
Save