add dynamic tls record patch
This commit is contained in:
@@ -1677,6 +1677,7 @@ ngx_ssl_create_connection(ngx_ssl_t *ssl, ngx_connection_t *c, ngx_uint_t flags)
|
||||
|
||||
sc->buffer = ((flags & NGX_SSL_BUFFER) != 0);
|
||||
sc->buffer_size = ssl->buffer_size;
|
||||
sc->dyn_rec = ssl->dyn_rec;
|
||||
|
||||
sc->session_ctx = ssl->ctx;
|
||||
|
||||
@@ -2643,6 +2644,41 @@ ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
/* Dynamic record resizing:
|
||||
We want the initial records to fit into one TCP segment
|
||||
so we don't get TCP HoL blocking due to TCP Slow Start.
|
||||
A connection always starts with small records, but after
|
||||
a given amount of records sent, we make the records larger
|
||||
to reduce header overhead.
|
||||
After a connection has idled for a given timeout, begin
|
||||
the process from the start. The actual parameters are
|
||||
configurable. If dyn_rec_timeout is 0, we assume dyn_rec is off. */
|
||||
|
||||
if (c->ssl->dyn_rec.timeout > 0 ) {
|
||||
|
||||
if (ngx_current_msec - c->ssl->dyn_rec_last_write >
|
||||
c->ssl->dyn_rec.timeout)
|
||||
{
|
||||
buf->end = buf->start + c->ssl->dyn_rec.size_lo;
|
||||
c->ssl->dyn_rec_records_sent = 0;
|
||||
|
||||
} else {
|
||||
if (c->ssl->dyn_rec_records_sent >
|
||||
c->ssl->dyn_rec.threshold * 2)
|
||||
{
|
||||
buf->end = buf->start + c->ssl->buffer_size;
|
||||
|
||||
} else if (c->ssl->dyn_rec_records_sent >
|
||||
c->ssl->dyn_rec.threshold)
|
||||
{
|
||||
buf->end = buf->start + c->ssl->dyn_rec.size_hi;
|
||||
|
||||
} else {
|
||||
buf->end = buf->start + c->ssl->dyn_rec.size_lo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (in && buf->last < buf->end && send < limit) {
|
||||
if (in->buf->last_buf || in->buf->flush) {
|
||||
flush = 1;
|
||||
@@ -2782,6 +2818,9 @@ ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size)
|
||||
|
||||
if (n > 0) {
|
||||
|
||||
c->ssl->dyn_rec_records_sent++;
|
||||
c->ssl->dyn_rec_last_write = ngx_current_msec;
|
||||
|
||||
if (c->ssl->saved_read_handler) {
|
||||
|
||||
c->read->handler = c->ssl->saved_read_handler;
|
||||
|
||||
@@ -86,10 +86,19 @@
|
||||
typedef struct ngx_ssl_ocsp_s ngx_ssl_ocsp_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_msec_t timeout;
|
||||
ngx_uint_t threshold;
|
||||
size_t size_lo;
|
||||
size_t size_hi;
|
||||
} ngx_ssl_dyn_rec_t;
|
||||
|
||||
|
||||
struct ngx_ssl_s {
|
||||
SSL_CTX *ctx;
|
||||
ngx_log_t *log;
|
||||
size_t buffer_size;
|
||||
ngx_ssl_dyn_rec_t dyn_rec;
|
||||
};
|
||||
|
||||
|
||||
@@ -128,6 +137,10 @@ struct ngx_ssl_connection_s {
|
||||
unsigned in_ocsp:1;
|
||||
unsigned early_preread:1;
|
||||
unsigned write_blocked:1;
|
||||
|
||||
ngx_ssl_dyn_rec_t dyn_rec;
|
||||
ngx_msec_t dyn_rec_last_write;
|
||||
ngx_uint_t dyn_rec_records_sent;
|
||||
};
|
||||
|
||||
|
||||
@@ -137,7 +150,7 @@ struct ngx_ssl_connection_s {
|
||||
#define NGX_SSL_DFLT_BUILTIN_SCACHE -5
|
||||
|
||||
|
||||
#define NGX_SSL_MAX_SESSION_SIZE 4096
|
||||
#define NGX_SSL_MAX_SESSION_SIZE 16384
|
||||
|
||||
typedef struct ngx_ssl_sess_id_s ngx_ssl_sess_id_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user