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 | * |
| 5 | * Copyright (C) 2000-2009 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 | 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 | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame^] | 26 | #include <types/lb_fwlc.h> |
| 27 | #include <types/lb_fwrr.h> |
| 28 | #include <types/lb_map.h> |
| 29 | #include <types/server.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 30 | |
Willy Tarreau | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame^] | 31 | /* Parameters for lbprm.algo. |
Willy Tarreau | df36614 | 2007-11-30 16:23:20 +0100 | [diff] [blame] | 32 | * The low part of the value is unique for each algo so that applying the mask |
| 33 | * BE_LB_ALGO returns a unique algorithm. |
| 34 | * The high part indicates specific properties. |
| 35 | */ |
| 36 | |
| 37 | /* Masks to extract algorithm properties */ |
| 38 | #define BE_LB_ALGO 0x000007FF /* mask to extract all algorithm flags */ |
| 39 | #define BE_LB_PROP_DYN 0x00000100 /* mask to match dynamic algorithms */ |
| 40 | #define BE_LB_PROP_L4 0x00000200 /* mask to match layer4-based algorithms */ |
| 41 | #define BE_LB_PROP_L7 0x00000400 /* mask to match layer7-based algorithms */ |
| 42 | |
| 43 | /* the algorithms themselves */ |
| 44 | #define BE_LB_ALGO_NONE 0x00000000 /* dispatch or transparent mode */ |
| 45 | #define BE_LB_ALGO_RR (BE_LB_PROP_DYN | 0x01) /* fast weighted round-robin mode (dynamic) */ |
| 46 | #define BE_LB_ALGO_SH (BE_LB_PROP_L4 | 0x02) /* balance on source IP hash */ |
| 47 | #define BE_LB_ALGO_UH (BE_LB_PROP_L7 | 0x03) /* balance on URI hash */ |
| 48 | #define BE_LB_ALGO_PH (BE_LB_PROP_L7 | 0x04) /* balance on URL parameter hash */ |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 49 | #define BE_LB_ALGO_LC (BE_LB_PROP_DYN | 0x05) /* fast weighted leastconn mode (dynamic) */ |
| 50 | #define BE_LB_ALGO_HH (BE_LB_PROP_L7 | 0x06) /* balance on Http Header value */ |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 51 | #define BE_LB_ALGO_RCH (BE_LB_PROP_L4 | 0x07) /* balance on RDP Cookie value */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 52 | |
| 53 | /* various constants */ |
Willy Tarreau | b698f0f | 2007-12-02 11:01:23 +0100 | [diff] [blame] | 54 | |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 55 | /* The scale factor between user weight and effective weight allows smooth |
Willy Tarreau | b698f0f | 2007-12-02 11:01:23 +0100 | [diff] [blame] | 56 | * weight modulation even with small weights (eg: 1). It should not be too high |
| 57 | * though because it limits the number of servers in FWRR mode in order to |
| 58 | * prevent any integer overflow. The max number of servers per backend is |
| 59 | * limited to about 2^32/255^2/scale ~= 66051/scale. A scale of 16 looks like |
| 60 | * a good value, as it allows more than 4000 servers per backend while leaving |
| 61 | * modulation steps of about 6% for servers with the lowest weight (1). |
| 62 | */ |
| 63 | #define BE_WEIGHT_SCALE 16 |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 64 | |
Willy Tarreau | 5b4c2b5 | 2009-10-03 11:21:53 +0200 | [diff] [blame^] | 65 | /* LB parameters for all algorithms */ |
| 66 | struct lbprm { |
| 67 | int algo; /* load balancing algorithm and variants: BE_LB_ALGO_* */ |
| 68 | int tot_wact, tot_wbck; /* total effective weights of active and backup servers */ |
| 69 | int tot_weight; /* total effective weight of servers participating to LB */ |
| 70 | int tot_used; /* total number of servers used for LB */ |
| 71 | int wmult; /* ratio between user weight and effective weight */ |
| 72 | int wdiv; /* ratio between effective weight and user weight */ |
| 73 | struct server *fbck; /* first backup server when !PR_O_USE_ALL_BK, or NULL */ |
| 74 | struct lb_map map; /* LB parameters for map-based algorithms */ |
| 75 | struct lb_fwrr fwrr; |
| 76 | struct lb_fwlc fwlc; |
| 77 | /* Call backs for some actions. Some may be NULL (thus should be ignored). */ |
| 78 | void (*update_server_eweight)(struct server *); /* to be called after eweight change */ |
| 79 | void (*set_server_status_up)(struct server *); /* to be called after status changes to UP */ |
| 80 | void (*set_server_status_down)(struct server *); /* to be called after status changes to DOWN */ |
| 81 | void (*server_take_conn)(struct server *); /* to be called when connection is assigned */ |
| 82 | void (*server_drop_conn)(struct server *); /* to be called when connection is dropped */ |
| 83 | }; |
| 84 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | #endif /* _TYPES_BACKEND_H */ |
| 86 | |
| 87 | /* |
| 88 | * Local variables: |
| 89 | * c-indent-level: 8 |
| 90 | * c-basic-offset: 8 |
| 91 | * End: |
| 92 | */ |