Willy TARREAU | 3dc0644 | 2006-06-15 21:48:13 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2 | * include/proto/stream.h |
| 3 | * This file defines everything related to streams. |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
Willy TARREAU | 3dc0644 | 2006-06-15 21:48:13 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 22 | #ifndef _PROTO_STREAM_H |
| 23 | #define _PROTO_STREAM_H |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 26 | #include <common/memory.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 27 | #include <types/stream.h> |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 28 | #include <proto/fd.h> |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 29 | #include <proto/freq_ctr.h> |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 30 | #include <proto/stick_table.h> |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 31 | #include <proto/task.h> |
Willy TARREAU | 3dc0644 | 2006-06-15 21:48:13 +0200 | [diff] [blame] | 32 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 33 | extern struct pool_head *pool2_stream; |
| 34 | extern struct list streams; |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 35 | extern struct list buffer_wq; |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 36 | |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 37 | extern struct data_cb sess_conn_cb; |
| 38 | |
Willy Tarreau | 73b65ac | 2015-04-08 18:26:29 +0200 | [diff] [blame] | 39 | struct stream *stream_new(struct session *sess, struct task *t, enum obj_type *origin); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 41 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 42 | int init_stream(); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 44 | /* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 45 | void stream_shutdown(struct stream *stream, int why); |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 46 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 47 | void stream_process_counters(struct stream *s); |
| 48 | void sess_change_server(struct stream *sess, struct server *newsrv); |
| 49 | struct task *process_stream(struct task *t); |
| 50 | void default_srv_error(struct stream *s, struct stream_interface *si); |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 51 | struct stkctr *smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 52 | int parse_track_counters(char **args, int *arg, |
| 53 | int section_type, struct proxy *curpx, |
| 54 | struct track_ctr_prm *prm, |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 55 | struct proxy *defpx, char **err); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 56 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 57 | /* Update the stream's backend and server time stats */ |
| 58 | void stream_update_time_stats(struct stream *s); |
| 59 | void __stream_offer_buffers(int rqlimit); |
| 60 | static inline void stream_offer_buffers(); |
| 61 | int stream_alloc_work_buffer(struct stream *s); |
| 62 | void stream_release_buffers(struct stream *s); |
| 63 | int stream_alloc_recv_buffer(struct channel *chn); |
Willy Tarreau | 4bfc580 | 2014-06-17 12:19:18 +0200 | [diff] [blame] | 64 | |
Willy Tarreau | b1ec8c4 | 2015-04-03 13:53:24 +0200 | [diff] [blame] | 65 | /* returns the session this stream belongs to */ |
| 66 | static inline struct session *strm_sess(const struct stream *strm) |
| 67 | { |
| 68 | return strm->sess; |
| 69 | } |
| 70 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 71 | /* returns the frontend this stream was initiated from */ |
| 72 | static inline struct proxy *strm_fe(const struct stream *strm) |
| 73 | { |
| 74 | return strm->sess->fe; |
| 75 | } |
| 76 | |
| 77 | /* returns the listener this stream was initiated from */ |
| 78 | static inline struct listener *strm_li(const struct stream *strm) |
| 79 | { |
| 80 | return strm->sess->listener; |
| 81 | } |
| 82 | |
| 83 | /* returns a pointer to the origin of the session which created this stream */ |
| 84 | static inline enum obj_type *strm_orig(const struct stream *strm) |
| 85 | { |
| 86 | return strm->sess->origin; |
| 87 | } |
| 88 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 89 | /* Remove the refcount from the stream to the tracked counters, and clear the |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 90 | * pointer to ensure this is only performed once. The caller is responsible for |
| 91 | * ensuring that the pointer is valid first. |
| 92 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 93 | static inline void stream_store_counters(struct stream *s) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 94 | { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 95 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 96 | int i; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 97 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 98 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 99 | if (!stkctr_entry(&s->stkctr[i])) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 100 | continue; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 101 | ptr = stktable_data_ptr(s->stkctr[i].table, stkctr_entry(&s->stkctr[i]), STKTABLE_DT_CONN_CUR); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 102 | if (ptr) |
| 103 | stktable_data_cast(ptr, conn_cur)--; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 104 | stkctr_entry(&s->stkctr[i])->ref_cnt--; |
| 105 | stksess_kill_if_expired(s->stkctr[i].table, stkctr_entry(&s->stkctr[i])); |
| 106 | stkctr_set_entry(&s->stkctr[i], NULL); |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 107 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 110 | /* Remove the refcount from the stream counters tracked at the content level if |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 111 | * any, and clear the pointer to ensure this is only performed once. The caller |
| 112 | * is responsible for ensuring that the pointer is valid first. |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 113 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 114 | static inline void stream_stop_content_counters(struct stream *s) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 115 | { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 116 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 117 | int i; |
Willy Tarreau | e348793 | 2010-06-18 21:03:20 +0200 | [diff] [blame] | 118 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 119 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 120 | if (!stkctr_entry(&s->stkctr[i])) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 121 | continue; |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 122 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 123 | if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_CONTENT)) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 124 | continue; |
| 125 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 126 | ptr = stktable_data_ptr(s->stkctr[i].table, stkctr_entry(&s->stkctr[i]), STKTABLE_DT_CONN_CUR); |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 127 | if (ptr) |
| 128 | stktable_data_cast(ptr, conn_cur)--; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 129 | stkctr_entry(&s->stkctr[i])->ref_cnt--; |
| 130 | stksess_kill_if_expired(s->stkctr[i].table, stkctr_entry(&s->stkctr[i])); |
| 131 | stkctr_set_entry(&s->stkctr[i], NULL); |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 132 | } |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 133 | } |
Willy Tarreau | e348793 | 2010-06-18 21:03:20 +0200 | [diff] [blame] | 134 | |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 135 | /* Increase total and concurrent connection count for stick entry <ts> of table |
| 136 | * <t>. The caller is responsible for ensuring that <t> and <ts> are valid |
| 137 | * pointers, and for calling this only once per connection. |
| 138 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 139 | static inline void stream_start_counters(struct stktable *t, struct stksess *ts) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 140 | { |
| 141 | void *ptr; |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 142 | |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 143 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR); |
| 144 | if (ptr) |
| 145 | stktable_data_cast(ptr, conn_cur)++; |
| 146 | |
| 147 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
| 148 | if (ptr) |
| 149 | stktable_data_cast(ptr, conn_cnt)++; |
| 150 | |
| 151 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE); |
| 152 | if (ptr) |
| 153 | update_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), |
| 154 | t->data_arg[STKTABLE_DT_CONN_RATE].u, 1); |
| 155 | if (tick_isset(t->expire)) |
| 156 | ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
| 157 | } |
| 158 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 159 | /* Enable tracking of stream counters as <stkctr> on stksess <ts>. The caller is |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 160 | * responsible for ensuring that <t> and <ts> are valid pointers. Some controls |
| 161 | * are performed to ensure the state can still change. |
| 162 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 163 | static inline void stream_track_stkctr(struct stkctr *ctr, struct stktable *t, struct stksess *ts) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 164 | { |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 165 | if (stkctr_entry(ctr)) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 166 | return; |
| 167 | |
| 168 | ts->ref_cnt++; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 169 | ctr->table = t; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 170 | stkctr_set_entry(ctr, ts); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 171 | stream_start_counters(t, ts); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 174 | /* Increase the number of cumulated HTTP requests in the tracked counters */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 175 | static void inline stream_inc_http_req_ctr(struct stream *s) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 176 | { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 177 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 178 | int i; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 179 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 180 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 181 | struct stkctr *stkctr = &s->stkctr[i]; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 182 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 183 | if (!stkctr_entry(stkctr)) { |
| 184 | stkctr = &s->sess->stkctr[i]; |
| 185 | if (!stkctr_entry(stkctr)) |
| 186 | continue; |
| 187 | } |
| 188 | |
| 189 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 190 | if (ptr) |
| 191 | stktable_data_cast(ptr, http_req_cnt)++; |
| 192 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 193 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 194 | if (ptr) |
| 195 | update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 196 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 200 | /* Increase the number of cumulated HTTP requests in the backend's tracked |
| 201 | * counters. We don't look up the session since it cannot happen in the bakcend. |
| 202 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 203 | static void inline stream_inc_be_http_req_ctr(struct stream *s) |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 204 | { |
| 205 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 206 | int i; |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 207 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 208 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 209 | struct stkctr *stkctr = &s->stkctr[i]; |
| 210 | |
| 211 | if (!stkctr_entry(stkctr)) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 212 | continue; |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 213 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 214 | if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_BACKEND)) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 215 | continue; |
| 216 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 217 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 218 | if (ptr) |
| 219 | stktable_data_cast(ptr, http_req_cnt)++; |
| 220 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 221 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 222 | if (ptr) |
| 223 | update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 224 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1); |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 228 | /* Increase the number of cumulated failed HTTP requests in the tracked |
| 229 | * counters. Only 4xx requests should be counted here so that we can |
| 230 | * distinguish between errors caused by client behaviour and other ones. |
| 231 | * Note that even 404 are interesting because they're generally caused by |
| 232 | * vulnerability scans. |
| 233 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 234 | static void inline stream_inc_http_err_ctr(struct stream *s) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 235 | { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 236 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 237 | int i; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 238 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 239 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 240 | struct stkctr *stkctr = &s->stkctr[i]; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 241 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 242 | if (!stkctr_entry(stkctr)) { |
| 243 | stkctr = &s->sess->stkctr[i]; |
| 244 | if (!stkctr_entry(stkctr)) |
| 245 | continue; |
| 246 | } |
| 247 | |
| 248 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 249 | if (ptr) |
| 250 | stktable_data_cast(ptr, http_err_cnt)++; |
| 251 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 252 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 253 | if (ptr) |
| 254 | update_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 255 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u, 1); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 259 | static void inline stream_add_srv_conn(struct stream *sess, struct server *srv) |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 260 | { |
| 261 | sess->srv_conn = srv; |
| 262 | LIST_ADD(&srv->actconns, &sess->by_srv); |
| 263 | } |
| 264 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 265 | static void inline stream_del_srv_conn(struct stream *sess) |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 266 | { |
| 267 | if (!sess->srv_conn) |
| 268 | return; |
| 269 | |
| 270 | sess->srv_conn = NULL; |
| 271 | LIST_DEL(&sess->by_srv); |
| 272 | } |
| 273 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 274 | static void inline stream_init_srv_conn(struct stream *sess) |
Willy Tarreau | 9bd0d74 | 2011-07-20 00:17:39 +0200 | [diff] [blame] | 275 | { |
| 276 | sess->srv_conn = NULL; |
| 277 | LIST_INIT(&sess->by_srv); |
| 278 | } |
| 279 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 280 | static inline void stream_offer_buffers() |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 281 | { |
| 282 | int avail; |
| 283 | |
| 284 | if (LIST_ISEMPTY(&buffer_wq)) |
| 285 | return; |
| 286 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 287 | /* all streams will need 1 buffer, so we can stop waking up streams |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 288 | * once we have enough of them to eat all the buffers. Note that we |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 289 | * don't really know if they are streams or just other tasks, but |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 290 | * that's a rough estimate. Similarly, for each cached event we'll need |
| 291 | * 1 buffer. If no buffer is currently used, always wake up the number |
| 292 | * of tasks we can offer a buffer based on what is allocated, and in |
| 293 | * any case at least one task per two reserved buffers. |
| 294 | */ |
| 295 | avail = pool2_buffer->allocated - pool2_buffer->used - global.tune.reserved_bufs / 2; |
| 296 | |
| 297 | if (avail > (int)run_queue) |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 298 | __stream_offer_buffers(avail); |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 301 | #endif /* _PROTO_STREAM_H */ |
Willy TARREAU | 3dc0644 | 2006-06-15 21:48:13 +0200 | [diff] [blame] | 302 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 303 | /* |
| 304 | * Local variables: |
| 305 | * c-indent-level: 8 |
| 306 | * c-basic-offset: 8 |
| 307 | * End: |
| 308 | */ |