Show
Ignore:
Timestamp:
01/23/03 16:34:53 (10 years ago)
Author:
ahu
Message:

more pdns recursor stats

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/pdns_recursor.cc

    r138 r140  
    2424#include <netdb.h> 
    2525#include <stdio.h> 
     26#include <signal.h> 
    2627#include <stdlib.h> 
    2728#include <unistd.h> 
     
    5051int d_serversock; 
    5152 
    52  
    53 /* 
    54 Jan 20 00:21:40 [48570] new question arrived for 'idealx.com|MX' from 127.0.0.1 
    55 Jan 20 00:21:40 [48571] new question arrived for 'idealx.com|MX' from 127.0.0.1 
    56 Jan 20 00:21:40 [48572] new question arrived for 'idealx.com|MX' from 127.0.0.1 
    57 Jan 20 00:21:40 [48573] new question arrived for 'idealx.com|MX' from 127.0.0.1 
    58 Jan 20 00:21:44 [48573] sent answer to question for 'idealx.com|MX' to 127.0.0.1, 0 answers, 0 additional, sent 2 packets, rcode=2 
    59 Jan 20 00:21:44 [48573] sent answer to question for 'idealx.com|MX' to 127.0.0.1, 0 answers, 0 additional, sent 2 packets, rcode=2 
    60 Jan 20 00:21:44 [48573] sent answer to question for 'idealx.com|MX' to 127.0.0.1, 0 answers, 0 additional, sent 2 packets, rcode=2 
    61 Jan 20 00:21:44 [48573] sent answer to question for 'idealx.com|MX' to 127.0.0.1, 0 answers, 0 additional, sent 2 packets, rcode=2 
    62 */ 
    63  
    6453struct PacketID 
    6554{ 
     
    8473} 
    8574 
    86 MTasker<PacketID,string> MT(200000); 
     75MTasker<PacketID,string> MT(100000); // could probably be way lower 
    8776 
    8877/* these two functions are used by LWRes */ 
     
    10897  return 1; 
    10998} 
    110  
    11199 
    112100typedef map<string,set<DNSResourceRecord> > cache_t; 
     
    119107    if(res) 
    120108      *res=j->second; 
    121     cacheHits++; 
     109 
    122110    return (unsigned int)j->second.begin()->ttl-time(0); 
    123111  } 
    124   cacheMisses++; 
     112 
    125113  return -1; 
    126114} 
     
    139127  // prime root cache 
    140128  static char*ips[]={"198.41.0.4", "128.9.0.107", "192.33.4.12", "128.8.10.90", "192.203.230.10", "192.5.5.241", "192.112.36.4", "128.63.2.53",  
    141                      "192.36.148.17","198.41.0.10", "193.0.14.129", "198.32.64.12", "202.12.27.33"}; 
     129                     "192.36.148.17","192.58.128.30", "193.0.14.129", "198.32.64.12", "202.12.27.33"}; 
    142130  DNSResourceRecord arr, nsrr; 
    143131  arr.qtype=QType::A; 
     
    165153{ 
    166154  try { 
     155    bool quiet=arg().mustDo("quiet"); 
    167156    DNSPacket P=*(DNSPacket *)p; 
    168157 
     
    175164 
    176165    SyncRes sr; 
    177     L<<Logger::Error<<"["<<MT.getTid()<<"] question for '"<<P.qdomain<<"|"<<P.qtype.getName()<<"' from "<<P.getRemote()<<endl; 
     166    if(!quiet) 
     167      L<<Logger::Error<<"["<<MT.getTid()<<"] question for '"<<P.qdomain<<"|"<<P.qtype.getName()<<"' from "<<P.getRemote()<<endl; 
     168 
    178169    sr.setId(MT.getTid()); 
    179170    if(!P.d.rd) 
     
    191182    const char *buffer=R->getData(); 
    192183    sendto(d_serversock,buffer,R->len,0,(struct sockaddr *)(R->remote),R->d_socklen); 
    193     L<<Logger::Error<<"["<<MT.getTid()<<"] answer to "<<(P.d.rd?"":"non-rd ")<<"question '"<<P.qdomain<<"|"<<P.qtype.getName(); 
    194     L<<"': "<<ntohs(R->d.ancount)<<" answers, "<<ntohs(R->d.arcount)<<" additional, took "<<sr.d_outqueries<<" packets, rcode="<<res<<endl; 
     184    if(!quiet) { 
     185      L<<Logger::Error<<"["<<MT.getTid()<<"] answer to "<<(P.d.rd?"":"non-rd ")<<"question '"<<P.qdomain<<"|"<<P.qtype.getName(); 
     186      L<<"': "<<ntohs(R->d.ancount)<<" answers, "<<ntohs(R->d.arcount)<<" additional, took "<<sr.d_outqueries<<" packets, rcode="<<res<<endl; 
     187    } 
     188     
     189    sr.d_outqueries ? cacheMisses++ : cacheHits++; 
    195190 
    196191    delete R; 
     
    273268} 
    274269int counter, qcounter; 
     270bool statsWanted; 
     271 
     272void usr1Handler(int) 
     273{ 
     274  statsWanted=true; 
     275} 
     276void doStats(void) 
     277{ 
     278  if(qcounter) { 
     279    L<<Logger::Error<<"stats: "<<qcounter<<" questions, "<<cache.size()<<" cache entries, "<<SyncRes::s_negcache.size()<<" negative entries, " 
     280     <<(int)((cacheHits*100.0)/(cacheHits+cacheMisses))<<"% cache hits"; 
     281    L<<Logger::Error<<", outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"<<endl; 
     282  } 
     283  statsWanted=false; 
     284} 
    275285 
    276286void houseKeeping(void *) 
     
    278288  static time_t last_stat, last_rootupdate; 
    279289 
    280   if(time(0)-last_stat>1800) { 
    281     if(qcounter) { 
    282       L<<Logger::Error<<"stats: "<<qcounter<<" questions, "<<cache.size()<<" cache entries, " 
    283        <<(int)((cacheHits*100.0)/(cacheHits+cacheMisses))<<"% cache hits"; 
    284       L<<Logger::Error<<", outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"<<endl; 
    285     } 
     290  if(time(0)-last_stat>1800) {  
     291    doStats(); 
    286292    last_stat=time(0); 
    287293  } 
     
    308314    arg().set("soa-serial-offset","Don't change")="0"; 
    309315    arg().set("aaaa-additional-processing","turn on to do AAAA additional processing (slow)")="off"; 
    310     arg().set("local-port","port to listen on")="5300"; 
     316    arg().set("local-port","port to listen on")="53"; 
    311317    arg().set("local-address","port to listen on")="0.0.0.0"; 
    312318    arg().set("trace","if we should output heaps of logging")="off"; 
    313     arg().set("daemon","Operate as a daemon")="no"; 
     319    arg().set("daemon","Operate as a daemon")="yes"; 
     320    arg().set("quiet","Suppress logging of questions and answers")="off"; 
     321    arg().set("config-dir","Location of configuration directory (recursor.conf)")=SYSCONFDIR; 
    314322    arg().setCmd("help","Provide a helpful message"); 
    315  
    316     arg().parse(argc, argv); 
     323    L.toConsole(Logger::Warning); 
     324    arg().laxParse(argc,argv); // do a lax parse 
     325 
     326    string configname=arg()["config-dir"]+"/recursor.conf"; 
     327    cleanSlashes(configname); 
     328 
     329    if(!arg().file(configname.c_str()))  
     330      L<<Logger::Warning<<"Unable to parse configuration file '"<<configname<<"'"<<endl; 
     331 
     332    arg().parse(argc,argv); 
     333 
    317334 
    318335    if(arg().mustDo("help")) { 
     
    322339    } 
    323340 
    324  
    325341    L.setName("pdns_recursor"); 
    326     L.toConsole(Logger::Warning); 
    327342 
    328343    if(arg().mustDo("trace")) 
     
    343358      daemonize(); 
    344359    } 
     360    signal(SIGUSR1,usr1Handler); 
     361 
    345362    for(;;) { 
    346363      while(MT.schedule()); // housekeeping, let threads do their thing 
    347364       
    348       if(!((counter++)%1000))  
     365      if(!((counter++)%100))  
    349366        MT.makeThread(houseKeeping,0); 
     367      if(statsWanted) 
     368        doStats(); 
    350369 
    351370      socklen_t addrlen=sizeof(fromaddr); 
     
    362381      FD_SET( d_serversock, &readfds ); 
    363382      int selret = select( max(d_clientsock,d_serversock) + 1, &readfds, NULL, NULL, &tv ); 
    364       if (selret == -1)  
     383      if(selret<=0)  
     384        if (selret == -1 && errno!=EINTR)  
    365385          throw AhuException("Select returned: "+stringerror()); 
    366       if(!selret) // nothing happened 
    367         continue; 
     386        else 
     387          continue; 
     388 
    368389       
    369390      if(FD_ISSET(d_clientsock,&readfds)) { // do we have a question response?