New stats for s24s code, this is debug, do not use in real world

dynamic-accesslists
erdgeist 18 years ago
parent c4f924810e
commit c350fa0b3c

@ -281,6 +281,8 @@ static void httpresponse( const int64 s, char *data ) {
mode = STATS_UDP; mode = STATS_UDP;
else if( !byte_diff(data,4,"s24s")) else if( !byte_diff(data,4,"s24s"))
mode = STATS_SLASH24S; mode = STATS_SLASH24S;
else if( !byte_diff(data,4,"s24S"))
mode = STATS_SLASH24S_OLD;
else else
HTTPERROR_400_PARAM; HTTPERROR_400_PARAM;
} }
@ -312,8 +314,21 @@ static void httpresponse( const int64 s, char *data ) {
if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500; if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500;
break; break;
case STATS_SLASH24S: case STATS_SLASH24S:
if( !( reply_size = return_stats_for_slash24s( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 64 ) ) ) HTTPERROR_500; {
ot_dword diff; struct timeval tv1, tv2; gettimeofday( &tv1, NULL );
if( !( reply_size = return_stats_for_slash24s( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 16 ) ) ) HTTPERROR_500;
gettimeofday( &tv2, NULL ); diff = ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + tv2.tv_usec - tv1.tv_usec;
reply_size += sprintf( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf + reply_size, "Time taken: %ld\n", diff );
break; break;
}
case STATS_SLASH24S_OLD:
{
ot_dword diff; struct timeval tv1, tv2; gettimeofday( &tv1, NULL );
if( !( reply_size = return_stats_for_slash24s_old( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 16 ) ) ) HTTPERROR_500;
gettimeofday( &tv2, NULL ); diff = ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + tv2.tv_usec - tv1.tv_usec;
reply_size += sprintf( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf + reply_size, "Time taken: %ld\n", diff );
break;
}
} }
break; break;

@ -641,7 +641,93 @@ size_t return_stats_for_tracker( char *reply, int mode ) {
return r - reply; return r - reply;
} }
/* This function collects 4096 /24s in 4096 possible
malloc blocks
*/
size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) { size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) {
#define NUM_TOPBITS 12
#define NUM_LOWBITS (24-NUM_TOPBITS)
#define NUM_BUFS (1<<NUM_TOPBITS)
#define NUM_S24S (1<<NUM_LOWBITS)
#define MSK_S24S (NUM_S24S-1)
ot_dword *counts[ NUM_BUFS ];
ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */
size_t i, j, k, l;
char *r = reply;
byte_zero( counts, sizeof( counts ) );
byte_zero( slash24s, amount * 2 * sizeof(ot_dword) );
r += sprintf( r, "Stats for all /24s with more than %ld announced torrents:\n\n", thresh );
for( i=0; i<256; ++i ) {
ot_vector *torrents_list = &all_torrents[i];
for( j=0; j<torrents_list->size; ++j ) {
ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
for( k=0; k<OT_POOLS_COUNT; ++k ) {
ot_peer *peers = peer_list->peers[k].data;
size_t numpeers = peer_list->peers[k].size;
for( l=0; l<numpeers; ++l ) {
ot_dword s24 = ntohl(*(ot_dword*)(peers+l)) >> 8;
ot_dword *count = counts[ s24 >> NUM_LOWBITS ];
if( !count ) {
count = malloc( sizeof(ot_dword) * NUM_S24S );
if( !count )
goto bailout_cleanup;
byte_zero( count, sizeof( ot_dword ) * NUM_S24S );
counts[ s24 >> NUM_LOWBITS ] = count;
}
count[ s24 & MSK_S24S ]++;
}
}
}
}
k = l = 0; /* Debug: count allocated bufs */
for( i=0; i < NUM_BUFS; ++i ) {
ot_dword *count = counts[i];
if( !counts[i] )
continue;
++k; /* Debug: count allocated bufs */
for( j=0; j < NUM_S24S; ++j ) {
if( count[j] > thresh ) {
/* This subnet seems to announce more torrents than the last in our list */
int insert_pos = amount - 1;
while( ( insert_pos >= 0 ) && ( count[j] > slash24s[ 2 * insert_pos ] ) )
--insert_pos;
++insert_pos;
memmove( slash24s + 2 * ( insert_pos + 1 ), slash24s + 2 * ( insert_pos ), 2 * sizeof( ot_dword ) * ( amount - insert_pos - 1 ) );
slash24s[ 2 * insert_pos ] = count[j];
slash24s[ 2 * insert_pos + 1 ] = ( i << NUM_TOPBITS ) + j;
if( slash24s[ 2 * amount - 2 ] > thresh )
thresh = slash24s[ 2 * amount - 2 ];
}
if( count[j] ) ++l;
}
free( count );
}
r += sprintf( r, "Allocated bufs: %zd, used s24s: %zd\n", k, l );
for( i=0; i < amount; ++i )
if( slash24s[ 2*i ] >= thresh ) {
ot_dword ip = slash24s[ 2*i +1 ];
r += sprintf( r, "% 10ld %d.%d.%d.0/24\n", (long)slash24s[ 2*i ], (int)(ip >> 16), (int)(255 & ( ip >> 8 )), (int)(ip & 255) );
}
return r - reply;
bailout_cleanup:
for( i=0; i < NUM_BUFS; ++i )
free( counts[i] );
return 0;
}
size_t return_stats_for_slash24s_old( char *reply, size_t amount, ot_dword thresh ) {
ot_word *count = malloc( 0x1000000 * sizeof(ot_word) ); ot_word *count = malloc( 0x1000000 * sizeof(ot_word) );
ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */ ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */
size_t i, j, k, l; size_t i, j, k, l;

@ -84,7 +84,7 @@ typedef struct {
int init_logic( const char * const serverdir ); int init_logic( const char * const serverdir );
void deinit_logic( void ); void deinit_logic( void );
enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT }; enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, STATS_SLASH24S_OLD, SYNC_IN, SYNC_OUT };
ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset ); ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset );
size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ); size_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 );
size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply );
size_t return_stats_for_tracker( char *reply, int mode ); size_t return_stats_for_tracker( char *reply, int mode );
size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ); size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh );
size_t return_stats_for_slash24s_old( char *reply, size_t amount, ot_dword thresh );
size_t return_memstat_for_tracker( char **reply ); size_t return_memstat_for_tracker( char **reply );
size_t return_changeset_for_tracker( char **reply ); size_t return_changeset_for_tracker( char **reply );
int add_changeset_to_tracker( ot_byte *data, size_t len ); int add_changeset_to_tracker( ot_byte *data, size_t len );

Loading…
Cancel
Save