|
101 | 101 | #include "name_alias.h" |
102 | 102 | #include "ut.h" |
103 | 103 | #include "pt_scaling.h" |
| 104 | +#include <limits.h> |
104 | 105 | #include "dset.h" |
105 | 106 | #include "pvar.h" |
106 | 107 | #include "blacklists.h" |
@@ -197,6 +198,56 @@ union route_name_var { |
197 | 198 | void *data; |
198 | 199 | } rn_tmp; |
199 | 200 |
|
| 201 | +/* A profile size number with an optional k/m/g suffix. A suffix-less |
| 202 | + * number passes through POSITIVE, keeping the profile's legacy unit |
| 203 | + * (process count for the worker scaler, MB for the memory arenas); a |
| 204 | + * suffixed number is normalized to KB and carried NEGATED, so the two |
| 205 | + * kinds survive yacc's plain-int value stack without a union member the |
| 206 | + * lexer's cfg.tab.h could not see the type of. scale_suffix_kb() encodes, |
| 207 | + * create_scaling_profile_units() decodes. */ |
| 208 | +static long scale_suffix_kb(long num, const char *suf) |
| 209 | +{ |
| 210 | + if (!suf || !suf[0] || suf[1] || num <= 0) |
| 211 | + return 0; |
| 212 | + switch (suf[0]) { |
| 213 | + case 'k': case 'K': return -num; |
| 214 | + case 'm': case 'M': |
| 215 | + return num > LONG_MAX / 1024 ? 0 : -(num * 1024); |
| 216 | + case 'g': case 'G': |
| 217 | + return num > LONG_MAX / (1024 * 1024) ? 0 : |
| 218 | + -(num * 1024 * 1024); |
| 219 | + } |
| 220 | + return 0; |
| 221 | +} |
| 222 | + |
| 223 | +/* wraps create_auto_scaling_profile(): when either size carries a suffix |
| 224 | + * (arrives negated, in KB), normalize BOTH to KB (a bare number is then |
| 225 | + * read as MB) and flag the profile, so hg_autoscale_apply() knows the |
| 226 | + * unit. Suffix-less profiles take the untouched legacy path - the worker |
| 227 | + * scaler never sees a change. */ |
| 228 | +static int create_scaling_profile_units(char *name, |
| 229 | + long up, int u_pct, int u_need, int u_win, |
| 230 | + long down, int d_pct, int d_cyc, int d_delay) |
| 231 | +{ |
| 232 | + struct scaling_profile *p; |
| 233 | + int kb = up < 0 || down < 0; |
| 234 | + |
| 235 | + if (kb) { |
| 236 | + up = up < 0 ? -up : up * 1024; |
| 237 | + down = down < 0 ? -down : down * 1024; |
| 238 | + } |
| 239 | + if (create_auto_scaling_profile(name, up, u_pct, u_need, u_win, |
| 240 | + down, d_pct, d_cyc, d_delay) < 0) |
| 241 | + return -1; |
| 242 | + if (kb) { |
| 243 | + p = get_scaling_profile(name); |
| 244 | + if (!p) |
| 245 | + return -1; |
| 246 | + p->mem_kb_units = 1; |
| 247 | + } |
| 248 | + return 0; |
| 249 | +} |
| 250 | + |
200 | 251 | #ifndef SHM_EXTRA_STATS |
201 | 252 | struct multi_str{ |
202 | 253 | char *s; |
@@ -408,6 +459,18 @@ extern int cfg_parse_only_routes; |
408 | 459 | %token ASYNC_TOKEN |
409 | 460 | %token LAUNCH_TOKEN |
410 | 461 | %token AUTO_SCALING_PROFILE |
| 462 | +%token SHM_AUTO_SCALING_PROFILE |
| 463 | +%token PKG_AUTO_SCALING_PROFILE |
| 464 | +%token HG_RAM_FLOOR_MB |
| 465 | +%token HG_AUTOSCALE_DRY_RUN |
| 466 | +%token SHM_GROW_GRANULE |
| 467 | +%token PKG_GROW_GRANULE |
| 468 | +%token HG_LOCK_STALL_US |
| 469 | +%token HG_GROW_AHEAD |
| 470 | +%token HG_INTERIOR_RELEASE |
| 471 | +%token HG_SCALING_CYCLE |
| 472 | +%token HG_SHRINK_STEP |
| 473 | +%token HG_MEM_CHECK |
411 | 474 | %token AUTO_SCALING_CYCLE |
412 | 475 | %token TIMER_WORKERS |
413 | 476 |
|
@@ -505,6 +568,7 @@ extern int cfg_parse_only_routes; |
505 | 568 | %type <sockid> listen_id_def |
506 | 569 | %type <sockid> phostport phostportrange |
507 | 570 | %type <bondlst> socket_bond_elems |
| 571 | +%type <intval> scale_size |
508 | 572 | %type <intval> proto port any_proto |
509 | 573 | %type <strval> host_sep |
510 | 574 | %type <intval> equalop compop matchop strop intop |
@@ -925,32 +989,40 @@ mpath_def_list: mpath_def_list COLON STRING {IFOR(); add_mpath($3);} |
925 | 989 | | STRING { IFOR(); add_mpath($1);} |
926 | 990 | ; |
927 | 991 |
|
| 992 | +scale_size: NUMBER { $$ = $1; } |
| 993 | + | NUMBER ID { |
| 994 | + $$ = scale_suffix_kb($1, $2); |
| 995 | + if ($$ == 0) |
| 996 | + yyerror("bad size suffix - use k, m or g"); |
| 997 | + } |
| 998 | + ; |
| 999 | + |
928 | 1000 | auto_scale_profile_def: |
929 | | - ID SCALE_UP_TO NUMBER ON NUMBER MODULO FOR |
| 1001 | + ID SCALE_UP_TO scale_size ON NUMBER MODULO FOR |
930 | 1002 | NUMBER CYCLES_WITHIN NUMBER |
931 | | - SCALE_DOWN_TO NUMBER ON NUMBER MODULO FOR |
| 1003 | + SCALE_DOWN_TO scale_size ON NUMBER MODULO FOR |
932 | 1004 | NUMBER CYCLES { IFOR(); |
933 | | - if (create_auto_scaling_profile($1,$3,$5,$8,$10, |
| 1005 | + if (create_scaling_profile_units($1,$3,$5,$8,$10, |
934 | 1006 | $12, $14, $17,10*$17)<0) |
935 | 1007 | yyerror("failed to create auto scaling profile"); |
936 | 1008 | } |
937 | | - | ID SCALE_UP_TO NUMBER ON NUMBER MODULO FOR |
| 1009 | + | ID SCALE_UP_TO scale_size ON NUMBER MODULO FOR |
938 | 1010 | NUMBER CYCLES |
939 | | - SCALE_DOWN_TO NUMBER ON NUMBER MODULO FOR |
| 1011 | + SCALE_DOWN_TO scale_size ON NUMBER MODULO FOR |
940 | 1012 | NUMBER CYCLES { IFOR(); |
941 | | - if (create_auto_scaling_profile($1,$3,$5,$8,$8, |
| 1013 | + if (create_scaling_profile_units($1,$3,$5,$8,$8, |
942 | 1014 | $11, $13, $16, 10*$16)<0) |
943 | 1015 | yyerror("failed to create auto scaling profile"); |
944 | 1016 | } |
945 | | - | ID SCALE_UP_TO NUMBER ON NUMBER MODULO FOR |
| 1017 | + | ID SCALE_UP_TO scale_size ON NUMBER MODULO FOR |
946 | 1018 | NUMBER CYCLES_WITHIN NUMBER { IFOR(); |
947 | | - if (create_auto_scaling_profile($1,$3,$5,$8,$10, |
| 1019 | + if (create_scaling_profile_units($1,$3,$5,$8,$10, |
948 | 1020 | 0, 0, 0, 0)<0) |
949 | 1021 | yyerror("failed to create auto scaling profile"); |
950 | 1022 | } |
951 | | - | ID SCALE_UP_TO NUMBER ON NUMBER MODULO FOR |
| 1023 | + | ID SCALE_UP_TO scale_size ON NUMBER MODULO FOR |
952 | 1024 | NUMBER CYCLES { IFOR(); |
953 | | - if (create_auto_scaling_profile($1,$3,$5,$8,$8, |
| 1025 | + if (create_scaling_profile_units($1,$3,$5,$8,$8, |
954 | 1026 | 0, 0, 0, 0)<0) |
955 | 1027 | yyerror("failed to create auto scaling profile"); |
956 | 1028 | } |
@@ -1649,6 +1721,85 @@ assign_stm: LOGLEVEL EQUAL snumber { IFOR(); |
1649 | 1721 | | AUTO_SCALING_PROFILE EQUAL error { |
1650 | 1722 | yyerror("bad auto-scaling profile definition"); |
1651 | 1723 | } |
| 1724 | + | SHM_AUTO_SCALING_PROFILE EQUAL ID { IFOR(); |
| 1725 | + hg_shm_profile_name=$3; } |
| 1726 | + | SHM_AUTO_SCALING_PROFILE EQUAL error { |
| 1727 | + yyerror("profile name expected"); |
| 1728 | + } |
| 1729 | + | PKG_AUTO_SCALING_PROFILE EQUAL ID { IFOR(); |
| 1730 | + hg_pkg_profile_name=$3; } |
| 1731 | + | PKG_AUTO_SCALING_PROFILE EQUAL error { |
| 1732 | + yyerror("profile name expected"); |
| 1733 | + } |
| 1734 | + | HG_RAM_FLOOR_MB EQUAL NUMBER { IFOR(); |
| 1735 | + hg_ram_floor_mb=$3; } |
| 1736 | + | HG_RAM_FLOOR_MB EQUAL error { |
| 1737 | + yyerror("integer value expected"); |
| 1738 | + } |
| 1739 | + | HG_AUTOSCALE_DRY_RUN EQUAL NUMBER { IFOR(); |
| 1740 | + hg_autoscale_dry_run=$3; } |
| 1741 | + | HG_AUTOSCALE_DRY_RUN EQUAL error { |
| 1742 | + yyerror("integer value expected"); |
| 1743 | + } |
| 1744 | + | SHM_GROW_GRANULE EQUAL scale_size { IFOR(); |
| 1745 | + /* scale_size: positive = MB, negated = KB */ |
| 1746 | + hg_shm_grow_granule = $3 < 0 ? |
| 1747 | + (unsigned long)(-$3) << 10 : |
| 1748 | + (unsigned long)$3 << 20; |
| 1749 | + } |
| 1750 | + | SHM_GROW_GRANULE EQUAL error { |
| 1751 | + yyerror("size expected (number, optional k/m/g)"); |
| 1752 | + } |
| 1753 | + | PKG_GROW_GRANULE EQUAL scale_size { IFOR(); |
| 1754 | + hg_pkg_grow_granule = $3 < 0 ? |
| 1755 | + (unsigned long)(-$3) << 10 : |
| 1756 | + (unsigned long)$3 << 20; |
| 1757 | + } |
| 1758 | + | PKG_GROW_GRANULE EQUAL error { |
| 1759 | + yyerror("size expected (number, optional k/m/g)"); |
| 1760 | + } |
| 1761 | + | HG_LOCK_STALL_US EQUAL NUMBER { IFOR(); |
| 1762 | + hg_lock_stall_us=$3; } |
| 1763 | + | HG_LOCK_STALL_US EQUAL error { |
| 1764 | + yyerror("integer value expected"); |
| 1765 | + } |
| 1766 | + | HG_GROW_AHEAD EQUAL NUMBER { IFOR(); |
| 1767 | + hg_grow_ahead=$3; } |
| 1768 | + | HG_GROW_AHEAD EQUAL error { |
| 1769 | + yyerror("integer value expected"); |
| 1770 | + } |
| 1771 | + | HG_INTERIOR_RELEASE EQUAL NUMBER { IFOR(); |
| 1772 | + hg_interior_release=$3; } |
| 1773 | + | HG_INTERIOR_RELEASE EQUAL error { |
| 1774 | + yyerror("integer value expected"); |
| 1775 | + } |
| 1776 | + | HG_SCALING_CYCLE EQUAL NUMBER { IFOR(); |
| 1777 | + if ($3 < 1) { |
| 1778 | + yyerror("hg_scaling_cycle must be at least 1 second"); |
| 1779 | + YYABORT; |
| 1780 | + } |
| 1781 | + hg_scaling_cycle=$3; } |
| 1782 | + | HG_SCALING_CYCLE EQUAL error { |
| 1783 | + yyerror("integer value expected"); |
| 1784 | + } |
| 1785 | + | HG_SHRINK_STEP EQUAL scale_size { IFOR(); |
| 1786 | + /* scale_size: positive = MB, negated = KB */ |
| 1787 | + hg_shrink_step = $3 < 0 ? |
| 1788 | + (unsigned long)(-$3) << 10 : |
| 1789 | + (unsigned long)$3 << 20; |
| 1790 | + } |
| 1791 | + | HG_SHRINK_STEP EQUAL error { |
| 1792 | + yyerror("size expected (number, optional k/m/g)"); |
| 1793 | + } |
| 1794 | + | HG_MEM_CHECK EQUAL NUMBER { IFOR(); |
| 1795 | + if ($3 < 0 || $3 > 2) { |
| 1796 | + yyerror("hg_mem_check must be 0, 1 or 2"); |
| 1797 | + YYABORT; |
| 1798 | + } |
| 1799 | + hg_mem_check=$3; } |
| 1800 | + | HG_MEM_CHECK EQUAL error { |
| 1801 | + yyerror("integer value expected"); |
| 1802 | + } |
1652 | 1803 | | AUTO_SCALING_CYCLE EQUAL NUMBER { IFOR(); |
1653 | 1804 | auto_scaling_cycle=$3; } |
1654 | 1805 | | AUTO_SCALING_CYCLE EQUAL error { |
|
0 commit comments