Changeset 639

Show
Ignore:
Timestamp:
27/07/08 21:52:22 (4 months ago)
Author:
smoku
Message:

Implemented MIO read throttling in c2s. Now we pause reading socket instead of disconnection on throttle.

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/c2s/c2s.c

    r636 r639  
    5959                    } 
    6060 
    61                     log_write(sess->c2s->log, LOG_NOTICE, "%d is throttled, disconnecting", sess->fd->fd); 
    62  
    63                     /* Disconnect the user.  Ideally we would just stop 
    64                        reading from their socket until the throttle time 
    65                        expires.  But that's difficult. */ 
    66                     sx_kill(s); 
    6761                    return -1; 
    6862                } 
     
    238232                        sess->stanza_rate_log = 1; 
    239233                    } 
    240  
    241                     log_write(sess->c2s->log, LOG_NOTICE, "%d is throttled, disconnecting", sess->fd->fd); 
    242  
    243                     /* Disconnect the user.  Ideally we would just stop 
    244                        reading from their socket and delay processing of this 
    245                        stanza until the throttle time expires.  But that's 
    246                        difficult. */ 
    247                     sx_kill(s); 
    248                     return -1; 
    249234                } 
    250235 
     
    519504 
    520505        if(rate_check(rt) == 0) { 
    521             log_write(c2s->log, LOG_NOTICE, "[%d] [%s] is being rate limited", fd->fd, ip); 
     506            log_write(c2s->log, LOG_NOTICE, "[%d] [%s] is being connect rate limited", fd->fd, ip); 
    522507            return 1; 
    523508        } 
  • trunk/c2s/main.c

    r636 r639  
    181181    c2s->stanza_size_limit = j_atoi(config_get_one(c2s->config, "io.limits.stanzasize", 0), 0); 
    182182 
     183    /* tweak timed checks with rate times */ 
     184    if(c2s->io_check_interval == 0) { 
     185        if(c2s->byte_rate_total != 0) 
     186            c2s->io_check_interval = c2s->byte_rate_wait; 
     187 
     188        if(c2s->stanza_rate_total != 0 && c2s->io_check_interval > c2s->stanza_rate_wait) 
     189            c2s->io_check_interval = c2s->stanza_rate_wait; 
     190    } 
     191 
    183192    str = config_get_one(c2s->config, "io.access.order", 0); 
    184193    if(str == NULL || strcmp(str, "deny,allow") != 0) 
     
    475484            } 
    476485 
    477             /* Using SSF is potentially dangerous, as SASL can alse set the 
     486            /* Using SSF is potentially dangerous, as SASL can also set the 
    478487             * SSF of the connection. However, SASL shouldn't do so until after 
    479488             * we've finished mechanism establishment  
     
    529538            } 
    530539 
     540            if(sess->rate != NULL && sess->rate->bad != 0 && rate_check(sess->rate) != 0) { 
     541                /* read the pending bytes when rate limit is no longer in effect */ 
     542                log_debug(ZONE, "reading throttled %d", sess->fd->fd); 
     543                sess->s->want_read = 1; 
     544                sx_can_read(sess->s); 
     545            } 
     546 
    531547        } while(xhash_iter_next(c2s->sessions)); 
    532548} 
     
    537553    char *config_file; 
    538554    int optchar; 
     555    int mio_timeout; 
    539556    sess_t sess; 
    540557    bres_t res; 
     
    706723    _c2s_router_connect(c2s); 
    707724 
     725    mio_timeout = ((c2s->io_check_interval != 0 && c2s->io_check_interval < 5) ? 
     726        c2s->io_check_interval : 5); 
     727 
    708728    while(!c2s_shutdown) { 
    709         mio_run(c2s->mio, 5); 
     729        mio_run(c2s->mio, mio_timeout); 
    710730 
    711731        if(c2s_logrotate) { 
  • trunk/etc/c2s.xml.dist.in

    r636 r639  
    209209           The format is: 
    210210 
    211              <stanzas seconds='Y' throttle='Z'>X</bytes> 
     211             <stanzas seconds='Y' throttle='Z'>X</stanzas> 
    212212 
    213213           Default Y 1, default Z is 5. Set X to 0 to disable --> 
  • trunk/sx/Makefile.am

    r635 r639  
    11noinst_LTLIBRARIES = libsx.la 
    22noinst_HEADERS = plugins.h sasl.h sx.h 
    3  
    4 SUBDIRS = 
    53 
    64libsx_la_SOURCES = callback.c chain.c client.c env.c error.c io.c server.c sx.c