Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame] | 2 | * include/types/backend.h |
| 3 | * This file assembles definitions for backends |
| 4 | * |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 5 | * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu |
Willy Tarreau | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame] | 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
| 22 | #ifndef _TYPES_BACKEND_H |
| 23 | #define _TYPES_BACKEND_H |
| 24 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 26 | #include <types/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 27 | #include <types/lb_fas.h> |
Willy Tarreau | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame] | 28 | #include <types/lb_fwlc.h> |
| 29 | #include <types/lb_fwrr.h> |
| 30 | #include <types/lb_map.h> |
| 31 | #include <types/server.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 32 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 33 | /* Parameters for lbprm.algo */ |
| 34 | |
| 35 | /* Lower bits define the kind of load balancing method, which means the type of |
| 36 | * algorithm, and which criterion it is based on. For this reason, those bits |
| 37 | * also include information about dependencies, so that the config parser can |
| 38 | * detect incompatibilities. |
Willy Tarreau | df36614 | 2007-11-30 16:23:20 +0100 | [diff] [blame] | 39 | */ |
| 40 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 41 | /* LB parameters are on the lower 8 bits. Depends on the LB kind. */ |
| 42 | |
| 43 | /* BE_LB_HASH_* is used with BE_LB_KIND_HI */ |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 44 | #define BE_LB_HASH_SRC 0x00000 /* hash source IP */ |
| 45 | #define BE_LB_HASH_URI 0x00001 /* hash HTTP URI */ |
| 46 | #define BE_LB_HASH_PRM 0x00002 /* hash HTTP URL parameter */ |
| 47 | #define BE_LB_HASH_HDR 0x00003 /* hash HTTP header value */ |
| 48 | #define BE_LB_HASH_RDP 0x00004 /* hash RDP cookie value */ |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 49 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 50 | /* BE_LB_RR_* is used with BE_LB_KIND_RR */ |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 51 | #define BE_LB_RR_DYN 0x00000 /* dynamic round robin (default) */ |
| 52 | #define BE_LB_RR_STATIC 0x00001 /* static round robin */ |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 53 | |
| 54 | /* BE_LB_CB_* is used with BE_LB_KIND_CB */ |
| 55 | #define BE_LB_CB_LC 0x00000 /* least-connections */ |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 56 | #define BE_LB_CB_FAS 0x00001 /* first available server (opposite of leastconn) */ |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 57 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 58 | #define BE_LB_PARM 0x000FF /* mask to get/clear the LB param */ |
| 59 | |
| 60 | /* Required input(s) */ |
| 61 | #define BE_LB_NEED_NONE 0x00000 /* no input needed */ |
| 62 | #define BE_LB_NEED_ADDR 0x00100 /* only source address needed */ |
| 63 | #define BE_LB_NEED_DATA 0x00200 /* some payload is needed */ |
| 64 | #define BE_LB_NEED_HTTP 0x00400 /* an HTTP request is needed */ |
| 65 | /* not used: 0x0800 */ |
| 66 | #define BE_LB_NEED 0x00F00 /* mask to get/clear dependencies */ |
| 67 | |
| 68 | /* Algorithm */ |
| 69 | #define BE_LB_KIND_NONE 0x00000 /* algorithm not set */ |
| 70 | #define BE_LB_KIND_RR 0x01000 /* round-robin */ |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 71 | #define BE_LB_KIND_CB 0x02000 /* connection-based */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 72 | #define BE_LB_KIND_HI 0x03000 /* hash of input (see hash inputs above) */ |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 73 | #define BE_LB_KIND 0x07000 /* mask to get/clear LB algorithm */ |
| 74 | |
| 75 | /* All known variants of load balancing algorithms. These can be cleared using |
| 76 | * the BE_LB_ALGO mask. For a check, using BE_LB_KIND is preferred. |
| 77 | */ |
| 78 | #define BE_LB_ALGO_NONE (BE_LB_KIND_NONE | BE_LB_NEED_NONE) /* not defined */ |
| 79 | #define BE_LB_ALGO_RR (BE_LB_KIND_RR | BE_LB_NEED_NONE) /* round robin */ |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 80 | #define BE_LB_ALGO_LC (BE_LB_KIND_CB | BE_LB_NEED_NONE | BE_LB_CB_LC) /* least connections */ |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 81 | #define BE_LB_ALGO_FAS (BE_LB_KIND_CB | BE_LB_NEED_NONE | BE_LB_CB_FAS) /* first available server */ |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 82 | #define BE_LB_ALGO_SRR (BE_LB_KIND_RR | BE_LB_NEED_NONE | BE_LB_RR_STATIC) /* static round robin */ |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 83 | #define BE_LB_ALGO_SH (BE_LB_KIND_HI | BE_LB_NEED_ADDR | BE_LB_HASH_SRC) /* hash: source IP */ |
| 84 | #define BE_LB_ALGO_UH (BE_LB_KIND_HI | BE_LB_NEED_HTTP | BE_LB_HASH_URI) /* hash: HTTP URI */ |
| 85 | #define BE_LB_ALGO_PH (BE_LB_KIND_HI | BE_LB_NEED_HTTP | BE_LB_HASH_PRM) /* hash: HTTP URL parameter */ |
| 86 | #define BE_LB_ALGO_HH (BE_LB_KIND_HI | BE_LB_NEED_HTTP | BE_LB_HASH_HDR) /* hash: HTTP header value */ |
| 87 | #define BE_LB_ALGO_RCH (BE_LB_KIND_HI | BE_LB_NEED_DATA | BE_LB_HASH_RDP) /* hash: RDP cookie value */ |
| 88 | #define BE_LB_ALGO (BE_LB_KIND | BE_LB_NEED | BE_LB_PARM ) /* mask to clear algo */ |
| 89 | |
| 90 | /* Higher bits define how a given criterion is mapped to a server. In fact it |
| 91 | * designates the LB function by itself. The dynamic algorithms will also have |
| 92 | * the DYN bit set. These flags are automatically set at the end of the parsing. |
| 93 | */ |
| 94 | #define BE_LB_LKUP_NONE 0x00000 /* not defined */ |
| 95 | #define BE_LB_LKUP_MAP 0x10000 /* static map based lookup */ |
| 96 | #define BE_LB_LKUP_RRTREE 0x20000 /* FWRR tree lookup */ |
| 97 | #define BE_LB_LKUP_LCTREE 0x30000 /* FWLC tree lookup */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 98 | #define BE_LB_LKUP_CHTREE 0x40000 /* consistent hash */ |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 99 | #define BE_LB_LKUP_FSTREE 0x50000 /* FAS tree lookup */ |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 100 | #define BE_LB_LKUP 0x70000 /* mask to get just the LKUP value */ |
| 101 | |
| 102 | /* additional properties */ |
| 103 | #define BE_LB_PROP_DYN 0x80000 /* bit to indicate a dynamic algorithm */ |
| 104 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 105 | /* hash types */ |
| 106 | #define BE_LB_HASH_MAP 0x000000 /* map-based hash (default) */ |
| 107 | #define BE_LB_HASH_CONS 0x100000 /* consistent hashbit to indicate a dynamic algorithm */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 108 | #define BE_LB_HASH_TYPE 0x100000 /* get/clear hash types */ |
| 109 | |
| 110 | /* additional modifier on top of the hash function (only avalanche right now) */ |
| 111 | #define BE_LB_HMOD_AVAL 0x200000 /* avalanche modifier */ |
| 112 | #define BE_LB_HASH_MOD 0x200000 /* get/clear hash modifier */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 113 | |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 114 | /* BE_LB_HFCN_* is the hash function, to be used with BE_LB_HASH_FUNC */ |
| 115 | #define BE_LB_HFCN_SDBM 0x000000 /* sdbm hash */ |
| 116 | #define BE_LB_HFCN_DJB2 0x400000 /* djb2 hash */ |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 117 | #define BE_LB_HFCN_WT6 0x800000 /* wt6 hash */ |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 118 | #define BE_LB_HFCN_CRC32 0xC00000 /* crc32 hash */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 119 | #define BE_LB_HASH_FUNC 0xC00000 /* get/clear hash function */ |
| 120 | |
| 121 | |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 122 | /* various constants */ |
Willy Tarreau | b698f0f | 2007-12-02 11:01:23 +0100 | [diff] [blame] | 123 | |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 124 | /* The scale factor between user weight and effective weight allows smooth |
Willy Tarreau | b698f0f | 2007-12-02 11:01:23 +0100 | [diff] [blame] | 125 | * weight modulation even with small weights (eg: 1). It should not be too high |
| 126 | * though because it limits the number of servers in FWRR mode in order to |
| 127 | * prevent any integer overflow. The max number of servers per backend is |
Godbach | a34bdc0 | 2013-07-22 07:44:53 +0800 | [diff] [blame] | 128 | * limited to about (2^32-1)/256^2/scale ~= 65535.9999/scale. A scale of 16 |
| 129 | * looks like a good value, as it allows 4095 servers per backend while leaving |
Willy Tarreau | b698f0f | 2007-12-02 11:01:23 +0100 | [diff] [blame] | 130 | * modulation steps of about 6% for servers with the lowest weight (1). |
| 131 | */ |
| 132 | #define BE_WEIGHT_SCALE 16 |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 133 | |
Willy Tarreau | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame] | 134 | /* LB parameters for all algorithms */ |
| 135 | struct lbprm { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 136 | int algo; /* load balancing algorithm and variants: BE_LB_* */ |
Willy Tarreau | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame] | 137 | int tot_wact, tot_wbck; /* total effective weights of active and backup servers */ |
| 138 | int tot_weight; /* total effective weight of servers participating to LB */ |
| 139 | int tot_used; /* total number of servers used for LB */ |
| 140 | int wmult; /* ratio between user weight and effective weight */ |
| 141 | int wdiv; /* ratio between effective weight and user weight */ |
| 142 | struct server *fbck; /* first backup server when !PR_O_USE_ALL_BK, or NULL */ |
| 143 | struct lb_map map; /* LB parameters for map-based algorithms */ |
| 144 | struct lb_fwrr fwrr; |
| 145 | struct lb_fwlc fwlc; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 146 | struct lb_chash chash; |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 147 | struct lb_fas fas; |
Willy Tarreau | 9580d16 | 2012-05-19 19:07:40 +0200 | [diff] [blame] | 148 | /* Call backs for some actions. Any of them may be NULL (thus should be ignored). */ |
Willy Tarreau | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame] | 149 | void (*update_server_eweight)(struct server *); /* to be called after eweight change */ |
| 150 | void (*set_server_status_up)(struct server *); /* to be called after status changes to UP */ |
| 151 | void (*set_server_status_down)(struct server *); /* to be called after status changes to DOWN */ |
| 152 | void (*server_take_conn)(struct server *); /* to be called when connection is assigned */ |
| 153 | void (*server_drop_conn)(struct server *); /* to be called when connection is dropped */ |
| 154 | }; |
| 155 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 156 | #endif /* _TYPES_BACKEND_H */ |
| 157 | |
| 158 | /* |
| 159 | * Local variables: |
| 160 | * c-indent-level: 8 |
| 161 | * c-basic-offset: 8 |
| 162 | * End: |
| 163 | */ |