diff options
author | erdgeist <> | 2007-11-16 00:23:42 +0000 |
---|---|---|
committer | erdgeist <> | 2007-11-16 00:23:42 +0000 |
commit | 6458a37d82aef8e910b2aed4cf25333e211482ae (patch) | |
tree | 619db62da7168b8979ec61913128fcbbefa0e128 /opentracker.c | |
parent | d3963803caab5b1cb30bb58b271dede1b731bbd8 (diff) |
introducing multithreaded full scrape creation.
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/opentracker.c b/opentracker.c index 501213d..06be4fa 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -193,15 +193,29 @@ static void sendiovecdata( const int64 s, int iovec_entries, struct iovec *iovec | |||
193 | size_t header_size, size = iovec_length( &iovec_entries, &iovector ); | 193 | size_t header_size, size = iovec_length( &iovec_entries, &iovector ); |
194 | tai6464 t; | 194 | tai6464 t; |
195 | 195 | ||
196 | /* No cookie? Bad socket. Leave. */ | ||
196 | if( !h ) { | 197 | if( !h ) { |
197 | iovec_free( &iovec_entries, &iovector ); | 198 | iovec_free( &iovec_entries, &iovector ); |
198 | return; | 199 | HTTPERROR_500; |
199 | } | 200 | } |
201 | |||
202 | /* If this socket collected request in a buffer, | ||
203 | free it now */ | ||
200 | if( h->flag & STRUCT_HTTP_FLAG_ARRAY_USED ) { | 204 | if( h->flag & STRUCT_HTTP_FLAG_ARRAY_USED ) { |
201 | h->flag &= ~STRUCT_HTTP_FLAG_ARRAY_USED; | 205 | h->flag &= ~STRUCT_HTTP_FLAG_ARRAY_USED; |
202 | array_reset( &h->request ); | 206 | array_reset( &h->request ); |
203 | } | 207 | } |
204 | 208 | ||
209 | /* If we came here, wait for the answer is over */ | ||
210 | h->flag &= ~STRUCT_HTTP_FLAG_WAITINGFORTASK; | ||
211 | |||
212 | /* Our answers never are 0 bytes. Return an error. */ | ||
213 | if( !iovec_entries || !iovector[0].iov_len ) { | ||
214 | iovec_free( &iovec_entries, &iovector ); | ||
215 | HTTPERROR_500; | ||
216 | } | ||
217 | |||
218 | /* Prepare space for http header */ | ||
205 | header = malloc( SUCCESS_HTTP_HEADER_LENGTH ); | 219 | header = malloc( SUCCESS_HTTP_HEADER_LENGTH ); |
206 | if( !header ) { | 220 | if( !header ) { |
207 | iovec_free( &iovec_entries, &iovector ); | 221 | iovec_free( &iovec_entries, &iovector ); |
@@ -212,7 +226,7 @@ static void sendiovecdata( const int64 s, int iovec_entries, struct iovec *iovec | |||
212 | 226 | ||
213 | iob_reset( &h->batch ); | 227 | iob_reset( &h->batch ); |
214 | iob_addbuf_free( &h->batch, header, header_size ); | 228 | iob_addbuf_free( &h->batch, header, header_size ); |
215 | 229 | ||
216 | /* Will move to ot_iovec.c */ | 230 | /* Will move to ot_iovec.c */ |
217 | for( i=0; i<iovec_entries; ++i ) | 231 | for( i=0; i<iovec_entries; ++i ) |
218 | iob_addbuf_munmap( &h->batch, iovector[i].iov_base, iovector[i].iov_len ); | 232 | iob_addbuf_munmap( &h->batch, iovector[i].iov_base, iovector[i].iov_len ); |
@@ -390,19 +404,15 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | |||
390 | 404 | ||
391 | /* Full scrape... you might want to limit that */ | 405 | /* Full scrape... you might want to limit that */ |
392 | if( !byte_diff( data, 12, "scrape HTTP/" ) ) { | 406 | if( !byte_diff( data, 12, "scrape HTTP/" ) ) { |
393 | int iovec_entries = 0; | ||
394 | struct iovec * iovector = NULL; | ||
395 | reply_size = return_fullscrape_for_tracker( &iovec_entries, &iovector ); | ||
396 | |||
397 | LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE\n", (unsigned int)(g_now - ot_start_time), h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | 407 | LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE\n", (unsigned int)(g_now - ot_start_time), h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); |
398 | #ifdef _DEBUG_HTTPERROR | 408 | #ifdef _DEBUG_HTTPERROR |
399 | write( 2, debug_request, l ); | 409 | write( 2, debug_request, l ); |
400 | #endif | 410 | #endif |
401 | if( !reply_size ) HTTPERROR_500; | 411 | /* Pass this task to the worker thread */ |
402 | 412 | h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; | |
403 | /* Stat keeping */ | 413 | fullscrape_deliver( s ); |
404 | stats_issue_event( EVENT_FULLSCRAPE, 1, reply_size); | 414 | io_dontwantread( s ); |
405 | return sendiovecdata( s, iovec_entries, iovector ); | 415 | return; |
406 | } | 416 | } |
407 | 417 | ||
408 | SCRAPE_WORKAROUND: | 418 | SCRAPE_WORKAROUND: |
@@ -714,9 +724,8 @@ static void handle_timeouted( void ) { | |||
714 | 724 | ||
715 | static void server_mainloop( ) { | 725 | static void server_mainloop( ) { |
716 | time_t next_timeout_check = g_now + OT_CLIENT_TIMEOUT_CHECKINTERVAL; | 726 | time_t next_timeout_check = g_now + OT_CLIENT_TIMEOUT_CHECKINTERVAL; |
717 | /* Later we will poll for finished tasks | ||
718 | struct iovec *iovector; | 727 | struct iovec *iovector; |
719 | int iovec_entries;*/ | 728 | int iovec_entries; |
720 | 729 | ||
721 | for( ; ; ) { | 730 | for( ; ; ) { |
722 | int64 i; | 731 | int64 i; |
@@ -733,9 +742,8 @@ static void server_mainloop( ) { | |||
733 | handle_read( i ); | 742 | handle_read( i ); |
734 | } | 743 | } |
735 | 744 | ||
736 | /* Later we will poll for finished tasks | ||
737 | while( ( i = mutex_workqueue_popresult( &iovec_entries, &iovector ) ) != -1 ) | 745 | while( ( i = mutex_workqueue_popresult( &iovec_entries, &iovector ) ) != -1 ) |
738 | sendiovecdata( i, iovec_entries, iovector ); */ | 746 | sendiovecdata( i, iovec_entries, iovector ); |
739 | 747 | ||
740 | while( ( i = io_canwrite( ) ) != -1 ) | 748 | while( ( i = io_canwrite( ) ) != -1 ) |
741 | handle_write( i ); | 749 | handle_write( i ); |
@@ -835,6 +843,8 @@ int main( int argc, char **argv ) { | |||
835 | if( trackerlogic_init( serverdir ) == -1 ) | 843 | if( trackerlogic_init( serverdir ) == -1 ) |
836 | panic( "Logic not started" ); | 844 | panic( "Logic not started" ); |
837 | 845 | ||
846 | fullscrape_init( ); | ||
847 | |||
838 | g_now = ot_start_time = time( NULL ); | 848 | g_now = ot_start_time = time( NULL ); |
839 | alarm(5); | 849 | alarm(5); |
840 | 850 | ||