diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2021-04-24 03:25:30 +0200 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2021-04-24 03:25:30 +0200 |
commit | 95f1780f0b6229a6f52b6dbad1a645b4e91c6b06 (patch) | |
tree | 152d4f281d0eb1380fe5c4d31f32341e5ac22e50 | |
parent | e87978860b1de6822db001cbc1d313694002ea28 (diff) |
Split huge iovecs over multiple io_batches
-rw-r--r-- | opentracker.c | 27 | ||||
-rw-r--r-- | ot_fullscrape.c | 2 | ||||
-rw-r--r-- | ot_http.c | 36 | ||||
-rw-r--r-- | ot_http.h | 3 |
4 files changed, 53 insertions, 15 deletions
diff --git a/opentracker.c b/opentracker.c index 441639a..cc0700c 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -156,7 +156,10 @@ static size_t header_complete( char * request, ssize_t byte_count ) { | |||
156 | static void handle_dead( const int64 sock ) { | 156 | static void handle_dead( const int64 sock ) { |
157 | struct http_data* cookie=io_getcookie( sock ); | 157 | struct http_data* cookie=io_getcookie( sock ); |
158 | if( cookie ) { | 158 | if( cookie ) { |
159 | iob_reset( &cookie->batch ); | 159 | size_t i; |
160 | for ( i = 0; i < cookie->batches; ++i) | ||
161 | iob_reset( cookie->batch + i ); | ||
162 | free( cookie->batch ); | ||
160 | array_reset( &cookie->request ); | 163 | array_reset( &cookie->request ); |
161 | if( cookie->flag & STRUCT_HTTP_FLAG_WAITINGFORTASK ) | 164 | if( cookie->flag & STRUCT_HTTP_FLAG_WAITINGFORTASK ) |
162 | mutex_workqueue_canceltask( sock ); | 165 | mutex_workqueue_canceltask( sock ); |
@@ -204,12 +207,22 @@ static void handle_read( const int64 sock, struct ot_workstruct *ws ) { | |||
204 | 207 | ||
205 | static void handle_write( const int64 sock ) { | 208 | static void handle_write( const int64 sock ) { |
206 | struct http_data* cookie=io_getcookie( sock ); | 209 | struct http_data* cookie=io_getcookie( sock ); |
207 | if( cookie ) { | 210 | size_t i; |
208 | int64 res = iob_send( sock, &cookie->batch ); | 211 | |
209 | if (res == 0 || res == -3) | 212 | /* Look for the first io_batch still containing bytes to write */ |
210 | handle_dead( sock ); | 213 | if( cookie ) |
211 | } else | 214 | for( i = 0; i < cookie->batches; ++i ) |
212 | handle_dead( sock ); | 215 | if( cookie->batch[i].bytesleft ) { |
216 | int64 res = iob_send( sock, cookie->batch + i ); | ||
217 | |||
218 | if( res == -3 ) | ||
219 | break; | ||
220 | |||
221 | if( res == -1 || res > 0 || i < cookie->batches - 1 ) | ||
222 | return; | ||
223 | } | ||
224 | |||
225 | handle_dead( sock ); | ||
213 | } | 226 | } |
214 | 227 | ||
215 | static void handle_accept( const int64 serversocket ) { | 228 | static void handle_accept( const int64 serversocket ) { |
diff --git a/ot_fullscrape.c b/ot_fullscrape.c index c3c6b34..5d115dc 100644 --- a/ot_fullscrape.c +++ b/ot_fullscrape.c | |||
@@ -191,7 +191,7 @@ static void fullscrape_make_gzip( int *iovec_entries, struct iovec **iovector, o | |||
191 | byte_zero( &strm, sizeof(strm) ); | 191 | byte_zero( &strm, sizeof(strm) ); |
192 | strm.next_out = (uint8_t*)r; | 192 | strm.next_out = (uint8_t*)r; |
193 | strm.avail_out = OT_SCRAPE_CHUNK_SIZE; | 193 | strm.avail_out = OT_SCRAPE_CHUNK_SIZE; |
194 | if( deflateInit2(&strm,7,Z_DEFLATED,31,8,Z_DEFAULT_STRATEGY) != Z_OK ) | 194 | if( deflateInit2(&strm,7,Z_DEFLATED,31,9,Z_DEFAULT_STRATEGY) != Z_OK ) |
195 | fprintf( stderr, "not ok.\n" ); | 195 | fprintf( stderr, "not ok.\n" ); |
196 | 196 | ||
197 | if( ( mode & TASK_TASK_MASK ) == TASK_FULLSCRAPE ) { | 197 | if( ( mode & TASK_TASK_MASK ) == TASK_FULLSCRAPE ) { |
@@ -31,6 +31,7 @@ | |||
31 | #include "ot_accesslist.h" | 31 | #include "ot_accesslist.h" |
32 | 32 | ||
33 | #define OT_MAXMULTISCRAPE_COUNT 64 | 33 | #define OT_MAXMULTISCRAPE_COUNT 64 |
34 | #define OT_BATCH_LIMIT (1024*1024*16) | ||
34 | extern char *g_redirecturl; | 35 | extern char *g_redirecturl; |
35 | 36 | ||
36 | char *g_stats_path; | 37 | char *g_stats_path; |
@@ -75,7 +76,13 @@ static void http_senddata( const int64 sock, struct ot_workstruct *ws ) { | |||
75 | } | 76 | } |
76 | 77 | ||
77 | memcpy( outbuf, ws->reply + written_size, ws->reply_size - written_size ); | 78 | memcpy( outbuf, ws->reply + written_size, ws->reply_size - written_size ); |
78 | iob_addbuf_free( &cookie->batch, outbuf, ws->reply_size - written_size ); | 79 | if ( !cookie->batch ) { |
80 | cookie->batch = malloc( sizeof(io_batch) ); | ||
81 | memset( cookie->batch, 0, sizeof(io_batch) ); | ||
82 | cookie->batches = 1; | ||
83 | } | ||
84 | |||
85 | iob_addbuf_free( cookie->batch, outbuf, ws->reply_size - written_size ); | ||
79 | 86 | ||
80 | /* writeable short data sockets just have a tcp timeout */ | 87 | /* writeable short data sockets just have a tcp timeout */ |
81 | if( !ws->keep_alive ) { | 88 | if( !ws->keep_alive ) { |
@@ -152,12 +159,29 @@ ssize_t http_sendiovecdata( const int64 sock, struct ot_workstruct *ws, int iove | |||
152 | else | 159 | else |
153 | header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %zd\r\n\r\n", size ); | 160 | header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %zd\r\n\r\n", size ); |
154 | 161 | ||
155 | iob_reset( &cookie->batch ); | 162 | if (!cookie->batch ) { |
156 | iob_addbuf_free( &cookie->batch, header, header_size ); | 163 | cookie->batch = malloc( sizeof(io_batch) ); |
164 | memset( cookie->batch, 0, sizeof(io_batch) ); | ||
165 | cookie->batches = 1; | ||
166 | } | ||
167 | iob_addbuf_free( cookie->batch, header, header_size ); | ||
168 | |||
169 | /* Split huge iovectors into separate io_batches */ | ||
170 | for( i=0; i<iovec_entries; ++i ) { | ||
171 | io_batch *current = cookie->batch + cookie->batches; | ||
172 | |||
173 | /* If the current batch's limit is reached, try to reallocate a new batch to work on */ | ||
174 | if( current->bytesleft > OT_BATCH_LIMIT ) { | ||
175 | io_batch * new_batch = realloc( current, (cookie->batches + 1) * sizeof(io_batch) ); | ||
176 | if( new_batch ) { | ||
177 | cookie->batches++; | ||
178 | current = cookie->batch = new_batch; | ||
179 | memset( current, 0, sizeof(io_batch) ); | ||
180 | } | ||
181 | } | ||
157 | 182 | ||
158 | /* Will move to ot_iovec.c */ | 183 | iob_addbuf_munmap( current, iovector[i].iov_base, iovector[i].iov_len ); |
159 | for( i=0; i<iovec_entries; ++i ) | 184 | } |
160 | iob_addbuf_munmap( &cookie->batch, iovector[i].iov_base, iovector[i].iov_len ); | ||
161 | free( iovector ); | 185 | free( iovector ); |
162 | 186 | ||
163 | /* writeable sockets timeout after 10 minutes */ | 187 | /* writeable sockets timeout after 10 minutes */ |
@@ -14,7 +14,8 @@ typedef enum { | |||
14 | 14 | ||
15 | struct http_data { | 15 | struct http_data { |
16 | array request; | 16 | array request; |
17 | io_batch batch; | 17 | io_batch *batch; |
18 | size_t batches; | ||
18 | ot_ip6 ip; | 19 | ot_ip6 ip; |
19 | STRUCT_HTTP_FLAG flag; | 20 | STRUCT_HTTP_FLAG flag; |
20 | }; | 21 | }; |