blob: 934e29dc830e197626c290c321edb2876d990293 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreauf8e8b762012-01-20 15:57:05 +01002 * include/proto/queue.h
3 * This file defines everything related to queues.
4 *
5 * Copyright (C) 2000-2012 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 Tarreaubaaee002006-06-26 02:48:02 +020021
22#ifndef _PROTO_QUEUE_H
23#define _PROTO_QUEUE_H
24
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020025#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020026#include <common/memory.h>
27#include <common/mini-clist.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020028
29#include <types/proxy.h>
30#include <types/queue.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020031#include <types/stream.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020032#include <types/server.h>
33#include <types/task.h>
34
Willy Tarreauf8e8b762012-01-20 15:57:05 +010035#include <proto/backend.h>
36
Willy Tarreaue4d7e552007-05-13 20:19:55 +020037extern struct pool_head *pool2_pendconn;
38
39int init_pendconn();
Willy Tarreau87b09662015-04-03 00:22:06 +020040struct stream *pendconn_get_next_strm(struct server *srv, struct proxy *px);
41struct pendconn *pendconn_add(struct stream *strm);
Willy Tarreaubaaee002006-06-26 02:48:02 +020042void pendconn_free(struct pendconn *p);
Willy Tarreau7c669d72008-06-20 15:04:11 +020043void process_srv_queue(struct server *s);
Willy Tarreaub17916e2006-10-15 15:17:57 +020044unsigned int srv_dynamic_maxconn(const struct server *s);
Willy Tarreau4aac7db2014-05-16 11:48:10 +020045int pendconn_redistribute(struct server *s);
46int pendconn_grab_from_px(struct server *s);
Willy Tarreaubaaee002006-06-26 02:48:02 +020047
48
49/* Returns the first pending connection for server <s>, which may be NULL if
50 * nothing is pending.
51 */
Willy Tarreaub17916e2006-10-15 15:17:57 +020052static inline struct pendconn *pendconn_from_srv(const struct server *s) {
Willy Tarreaubaaee002006-06-26 02:48:02 +020053 if (!s->nbpend)
54 return NULL;
55
56 return LIST_ELEM(s->pendconns.n, struct pendconn *, list);
57}
58
59/* Returns the first pending connection for proxy <px>, which may be NULL if
60 * nothing is pending.
61 */
Willy Tarreaub17916e2006-10-15 15:17:57 +020062static inline struct pendconn *pendconn_from_px(const struct proxy *px) {
Willy Tarreaubaaee002006-06-26 02:48:02 +020063 if (!px->nbpend)
64 return NULL;
65
66 return LIST_ELEM(px->pendconns.n, struct pendconn *, list);
67}
68
Willy Tarreauc35362a2014-04-25 13:58:37 +020069/* Returns 0 if all slots are full on a server, or 1 if there are slots available. */
70static inline int server_has_room(const struct server *s) {
71 return !s->maxconn || s->cur_sess < srv_dynamic_maxconn(s);
72}
73
Willy Tarreaubaaee002006-06-26 02:48:02 +020074/* returns 0 if nothing has to be done for server <s> regarding queued connections,
Willy Tarreau922a8062008-12-04 09:33:58 +010075 * and non-zero otherwise. If the server is down, we only check its own queue. Suited
76 * for and if/else usage.
Willy Tarreaubaaee002006-06-26 02:48:02 +020077 */
Willy Tarreaub17916e2006-10-15 15:17:57 +020078static inline int may_dequeue_tasks(const struct server *s, const struct proxy *p) {
Willy Tarreau87eb1d62014-05-13 18:51:40 +020079 return (s && (s->nbpend || (p->nbpend && srv_is_usable(s))) &&
Willy Tarreau7c669d72008-06-20 15:04:11 +020080 (!s->maxconn || s->cur_sess < srv_dynamic_maxconn(s)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020081}
82
83#endif /* _PROTO_QUEUE_H */
84
85/*
86 * Local variables:
87 * c-indent-level: 8
88 * c-basic-offset: 8
89 * End:
90 */