Changeset 8fab37d78032b4009b127dc2d5c06b71a627ebd5

Show
Ignore:
Timestamp:
08/28/10 23:47:53 (18 months ago)
Author:
Antti-Juhani Kaijanaho <antti-juhani@…>
Children:
62231ec0359b34f6a82b6688a7af97f2eb2ede10
Parents:
e044cc70b8bbba183fdf396ddbc00b2407eb5bea
git-committer:
Antti-Juhani Kaijanaho <antti-juhani@…> (08/28/10 23:47:53)
Message:

[http::connection] Kill idle connections.

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

Location:
http
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • http/connection.cc

    r6197546 r8fab37d  
    4545                , startup_timestamp 
    4646                  (boost::posix_time::second_clock::universal_time()) 
     47                , request_timestamp(startup_timestamp) 
     48                , num_requests(0) 
     49                , idle(false) 
    4750        { 
    4851                acc.async_accept(peer, ep, 
     
    116119                if (ec) { abort(self, ec); return; } 
    117120 
     121                self->idle = true; 
     122 
    118123                async_read_until(self->speer, self->readbuf, "\r\n\r\n", 
    119124                                 bind(&connection::got_request, 
     
    130135                using boost::bind; 
    131136                using boost::shared_ptr; 
     137 
     138                self->idle = false; 
     139                ++self->num_requests; 
    132140 
    133141                if (ec == boost::asio::error::eof) 
     
    255263                } 
    256264 
    257                 boost::posix_time::ptime reqtime = boost::posix_time::microsec_clock::universal_time(); 
     265                self->request_timestamp = 
     266                        boost::posix_time::microsec_clock::universal_time(); 
    258267 
    259268                if (self->srv_cb.do_log_protocol_details()) 
     
    317326                ll << self->loghead << (req ? req->logbit() : "") << " "  
    318327                   << resp->logbit() 
    319                    << "; " << boost::posix_time::microsec_clock::universal_time() - reqtime;  
     328                   << "; " 
     329                   << boost::posix_time::microsec_clock::universal_time() - 
     330                        self->request_timestamp; 
    320331                ll.close(); 
    321332 
     
    349360        } 
    350361 
    351         void connection::tick(bool) 
    352         { 
    353                 // FIXME 
     362        void connection::tick(bool stats) 
     363        { 
     364                using namespace boost::posix_time; 
     365                ptime now = microsec_clock::universal_time(); 
     366                bool kill = idle && num_requests != 0 && 
     367                        now - request_timestamp > minutes(10); 
     368 
     369                if (stats || kill) 
     370                { 
     371                        logger::logline ll; 
     372                        ll << loghead 
     373                           << " age " 
     374                           << now - startup_timestamp 
     375                           << "; " 
     376                           << (idle ? "idle " : "busy ") 
     377                           << now - request_timestamp 
     378                           << "; served " << num_requests << " requests"; 
     379                        if (kill) ll << "; killing"; 
     380                } 
     381                if (kill) speer.kill(); 
    354382        } 
    355383 
  • http/connection.hh

    r6197546 r8fab37d  
    8383 
    8484                boost::posix_time::ptime startup_timestamp; 
     85                boost::posix_time::ptime request_timestamp; 
     86                size_t num_requests; 
     87                bool idle; 
    8588 
    8689                boost::asio::streambuf readbuf;