summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-09-26 16:49:13 +0000
committererdgeist <>2007-09-26 16:49:13 +0000
commitc350fa0b3c323979f73d079d389219e7f98edc1b (patch)
tree61bb2ce1140874c5d5db98c26a043d836ae5d5ea
parentc4f924810ee0aa390ccbcf306149512646875757 (diff)
New stats for s24s code, this is debug, do not use in real world
-rw-r--r--opentracker.c17
-rw-r--r--trackerlogic.c86
-rw-r--r--trackerlogic.h3
3 files changed, 104 insertions, 2 deletions
diff --git a/opentracker.c b/opentracker.c
index 646184c..02aeb4a 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -281,6 +281,8 @@ static void httpresponse( const int64 s, char *data ) {
281 mode = STATS_UDP; 281 mode = STATS_UDP;
282 else if( !byte_diff(data,4,"s24s")) 282 else if( !byte_diff(data,4,"s24s"))
283 mode = STATS_SLASH24S; 283 mode = STATS_SLASH24S;
284 else if( !byte_diff(data,4,"s24S"))
285 mode = STATS_SLASH24S_OLD;
284 else 286 else
285 HTTPERROR_400_PARAM; 287 HTTPERROR_400_PARAM;
286 } 288 }
@@ -312,8 +314,21 @@ static void httpresponse( const int64 s, char *data ) {
312 if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500; 314 if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500;
313 break; 315 break;
314 case STATS_SLASH24S: 316 case STATS_SLASH24S:
315 if( !( reply_size = return_stats_for_slash24s( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 64 ) ) ) HTTPERROR_500; 317{
318 ot_dword diff; struct timeval tv1, tv2; gettimeofday( &tv1, NULL );
319 if( !( reply_size = return_stats_for_slash24s( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 16 ) ) ) HTTPERROR_500;
320 gettimeofday( &tv2, NULL ); diff = ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + tv2.tv_usec - tv1.tv_usec;
321 reply_size += sprintf( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf + reply_size, "Time taken: %ld\n", diff );
316 break; 322 break;
323}
324 case STATS_SLASH24S_OLD:
325{
326 ot_dword diff; struct timeval tv1, tv2; gettimeofday( &tv1, NULL );
327 if( !( reply_size = return_stats_for_slash24s_old( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 16 ) ) ) HTTPERROR_500;
328 gettimeofday( &tv2, NULL ); diff = ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + tv2.tv_usec - tv1.tv_usec;
329 reply_size += sprintf( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf + reply_size, "Time taken: %ld\n", diff );
330 break;
331}
317 } 332 }
318 break; 333 break;
319 334
diff --git a/trackerlogic.c b/trackerlogic.c
index 0777c54..7d50ed4 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -641,7 +641,93 @@ size_t return_stats_for_tracker( char *reply, int mode ) {
641 return r - reply; 641 return r - reply;
642} 642}
643 643
644/* This function collects 4096 /24s in 4096 possible
645 malloc blocks
646*/
644size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) { 647size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) {
648
649#define NUM_TOPBITS 12
650#define NUM_LOWBITS (24-NUM_TOPBITS)
651#define NUM_BUFS (1<<NUM_TOPBITS)
652#define NUM_S24S (1<<NUM_LOWBITS)
653#define MSK_S24S (NUM_S24S-1)
654
655 ot_dword *counts[ NUM_BUFS ];
656 ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */
657 size_t i, j, k, l;
658 char *r = reply;
659
660 byte_zero( counts, sizeof( counts ) );
661 byte_zero( slash24s, amount * 2 * sizeof(ot_dword) );
662
663 r += sprintf( r, "Stats for all /24s with more than %ld announced torrents:\n\n", thresh );
664
665 for( i=0; i<256; ++i ) {
666 ot_vector *torrents_list = &all_torrents[i];
667 for( j=0; j<torrents_list->size; ++j ) {
668 ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
669 for( k=0; k<OT_POOLS_COUNT; ++k ) {
670 ot_peer *peers = peer_list->peers[k].data;
671 size_t numpeers = peer_list->peers[k].size;
672 for( l=0; l<numpeers; ++l ) {
673 ot_dword s24 = ntohl(*(ot_dword*)(peers+l)) >> 8;
674 ot_dword *count = counts[ s24 >> NUM_LOWBITS ];
675 if( !count ) {
676 count = malloc( sizeof(ot_dword) * NUM_S24S );
677 if( !count )
678 goto bailout_cleanup;
679 byte_zero( count, sizeof( ot_dword ) * NUM_S24S );
680 counts[ s24 >> NUM_LOWBITS ] = count;
681 }
682 count[ s24 & MSK_S24S ]++;
683 }
684 }
685 }
686 }
687
688 k = l = 0; /* Debug: count allocated bufs */
689 for( i=0; i < NUM_BUFS; ++i ) {
690 ot_dword *count = counts[i];
691 if( !counts[i] )
692 continue;
693 ++k; /* Debug: count allocated bufs */
694 for( j=0; j < NUM_S24S; ++j ) {
695 if( count[j] > thresh ) {
696 /* This subnet seems to announce more torrents than the last in our list */
697 int insert_pos = amount - 1;
698 while( ( insert_pos >= 0 ) && ( count[j] > slash24s[ 2 * insert_pos ] ) )
699 --insert_pos;
700 ++insert_pos;
701 memmove( slash24s + 2 * ( insert_pos + 1 ), slash24s + 2 * ( insert_pos ), 2 * sizeof( ot_dword ) * ( amount - insert_pos - 1 ) );
702 slash24s[ 2 * insert_pos ] = count[j];
703 slash24s[ 2 * insert_pos + 1 ] = ( i << NUM_TOPBITS ) + j;
704 if( slash24s[ 2 * amount - 2 ] > thresh )
705 thresh = slash24s[ 2 * amount - 2 ];
706 }
707 if( count[j] ) ++l;
708 }
709 free( count );
710 }
711
712 r += sprintf( r, "Allocated bufs: %zd, used s24s: %zd\n", k, l );
713
714 for( i=0; i < amount; ++i )
715 if( slash24s[ 2*i ] >= thresh ) {
716 ot_dword ip = slash24s[ 2*i +1 ];
717 r += sprintf( r, "% 10ld %d.%d.%d.0/24\n", (long)slash24s[ 2*i ], (int)(ip >> 16), (int)(255 & ( ip >> 8 )), (int)(ip & 255) );
718 }
719
720 return r - reply;
721
722bailout_cleanup:
723
724 for( i=0; i < NUM_BUFS; ++i )
725 free( counts[i] );
726
727 return 0;
728}
729
730size_t return_stats_for_slash24s_old( char *reply, size_t amount, ot_dword thresh ) {
645 ot_word *count = malloc( 0x1000000 * sizeof(ot_word) ); 731 ot_word *count = malloc( 0x1000000 * sizeof(ot_word) );
646 ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */ 732 ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */
647 size_t i, j, k, l; 733 size_t i, j, k, l;
diff --git a/trackerlogic.h b/trackerlogic.h
index cb67244..35dd9c8 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -84,7 +84,7 @@ typedef struct {
84int init_logic( const char * const serverdir ); 84int init_logic( const char * const serverdir );
85void deinit_logic( void ); 85void deinit_logic( void );
86 86
87enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT }; 87enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, STATS_SLASH24S_OLD, SYNC_IN, SYNC_OUT };
88 88
89ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset ); 89ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset );
90size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ); 90size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp );
@@ -94,6 +94,7 @@ size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply );
94size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); 94size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply );
95size_t return_stats_for_tracker( char *reply, int mode ); 95size_t return_stats_for_tracker( char *reply, int mode );
96size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ); 96size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh );
97size_t return_stats_for_slash24s_old( char *reply, size_t amount, ot_dword thresh );
97size_t return_memstat_for_tracker( char **reply ); 98size_t return_memstat_for_tracker( char **reply );
98size_t return_changeset_for_tracker( char **reply ); 99size_t return_changeset_for_tracker( char **reply );
99int add_changeset_to_tracker( ot_byte *data, size_t len ); 100int add_changeset_to_tracker( ot_byte *data, size_t len );