|
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; |
@@ -411,6 +462,18 @@ extern int cfg_parse_only_routes; |
411 | 462 | %token ASYNC_TOKEN |
412 | 463 | %token LAUNCH_TOKEN |
413 | 464 | %token AUTO_SCALING_PROFILE |
| 465 | +%token SHM_AUTO_SCALING_PROFILE |
| 466 | +%token PKG_AUTO_SCALING_PROFILE |
| 467 | +%token HG_RAM_FLOOR_MB |
| 468 | +%token HG_AUTOSCALE_DRY_RUN |
| 469 | +%token SHM_GROW_GRANULE |
| 470 | +%token PKG_GROW_GRANULE |
| 471 | +%token HG_LOCK_STALL_US |
| 472 | +%token HG_GROW_AHEAD |
| 473 | +%token HG_INTERIOR_RELEASE |
| 474 | +%token HG_SCALING_CYCLE |
| 475 | +%token HG_SHRINK_STEP |
| 476 | +%token HG_MEM_CHECK |
414 | 477 | %token AUTO_SCALING_CYCLE |
415 | 478 | %token TIMER_WORKERS |
416 | 479 |
|
@@ -508,6 +571,7 @@ extern int cfg_parse_only_routes; |
508 | 571 | %type <sockid> listen_id_def |
509 | 572 | %type <sockid> phostport phostportrange |
510 | 573 | %type <bondlst> socket_bond_elems |
| 574 | +%type <intval> scale_size |
511 | 575 | %type <intval> proto port any_proto |
512 | 576 | %type <strval> host_sep |
513 | 577 | %type <intval> equalop compop matchop strop intop |
@@ -928,32 +992,40 @@ mpath_def_list: mpath_def_list COLON STRING {IFOR(); add_mpath($3);} |
928 | 992 | | STRING { IFOR(); add_mpath($1);} |
929 | 993 | ; |
930 | 994 |
|
| 995 | +scale_size: NUMBER { $$ = $1; } |
| 996 | + | NUMBER ID { |
| 997 | + $$ = scale_suffix_kb($1, $2); |
| 998 | + if ($$ == 0) |
| 999 | + yyerror("bad size suffix - use k, m or g"); |
| 1000 | + } |
| 1001 | + ; |
| 1002 | + |
931 | 1003 | auto_scale_profile_def: |
932 | | - ID SCALE_UP_TO NUMBER ON NUMBER MODULO FOR |
| 1004 | + ID SCALE_UP_TO scale_size ON NUMBER MODULO FOR |
933 | 1005 | NUMBER CYCLES_WITHIN NUMBER |
934 | | - SCALE_DOWN_TO NUMBER ON NUMBER MODULO FOR |
| 1006 | + SCALE_DOWN_TO scale_size ON NUMBER MODULO FOR |
935 | 1007 | NUMBER CYCLES { IFOR(); |
936 | | - if (create_auto_scaling_profile($1,$3,$5,$8,$10, |
| 1008 | + if (create_scaling_profile_units($1,$3,$5,$8,$10, |
937 | 1009 | $12, $14, $17,10*$17)<0) |
938 | 1010 | yyerror("failed to create auto scaling profile"); |
939 | 1011 | } |
940 | | - | ID SCALE_UP_TO NUMBER ON NUMBER MODULO FOR |
| 1012 | + | ID SCALE_UP_TO scale_size ON NUMBER MODULO FOR |
941 | 1013 | NUMBER CYCLES |
942 | | - SCALE_DOWN_TO NUMBER ON NUMBER MODULO FOR |
| 1014 | + SCALE_DOWN_TO scale_size ON NUMBER MODULO FOR |
943 | 1015 | NUMBER CYCLES { IFOR(); |
944 | | - if (create_auto_scaling_profile($1,$3,$5,$8,$8, |
| 1016 | + if (create_scaling_profile_units($1,$3,$5,$8,$8, |
945 | 1017 | $11, $13, $16, 10*$16)<0) |
946 | 1018 | yyerror("failed to create auto scaling profile"); |
947 | 1019 | } |
948 | | - | ID SCALE_UP_TO NUMBER ON NUMBER MODULO FOR |
| 1020 | + | ID SCALE_UP_TO scale_size ON NUMBER MODULO FOR |
949 | 1021 | NUMBER CYCLES_WITHIN NUMBER { IFOR(); |
950 | | - if (create_auto_scaling_profile($1,$3,$5,$8,$10, |
| 1022 | + if (create_scaling_profile_units($1,$3,$5,$8,$10, |
951 | 1023 | 0, 0, 0, 0)<0) |
952 | 1024 | yyerror("failed to create auto scaling profile"); |
953 | 1025 | } |
954 | | - | ID SCALE_UP_TO NUMBER ON NUMBER MODULO FOR |
| 1026 | + | ID SCALE_UP_TO scale_size ON NUMBER MODULO FOR |
955 | 1027 | NUMBER CYCLES { IFOR(); |
956 | | - if (create_auto_scaling_profile($1,$3,$5,$8,$8, |
| 1028 | + if (create_scaling_profile_units($1,$3,$5,$8,$8, |
957 | 1029 | 0, 0, 0, 0)<0) |
958 | 1030 | yyerror("failed to create auto scaling profile"); |
959 | 1031 | } |
@@ -1673,6 +1745,85 @@ assign_stm: LOGLEVEL EQUAL snumber { IFOR(); |
1673 | 1745 | | AUTO_SCALING_PROFILE EQUAL error { |
1674 | 1746 | yyerror("bad auto-scaling profile definition"); |
1675 | 1747 | } |
| 1748 | + | SHM_AUTO_SCALING_PROFILE EQUAL ID { IFOR(); |
| 1749 | + hg_shm_profile_name=$3; } |
| 1750 | + | SHM_AUTO_SCALING_PROFILE EQUAL error { |
| 1751 | + yyerror("profile name expected"); |
| 1752 | + } |
| 1753 | + | PKG_AUTO_SCALING_PROFILE EQUAL ID { IFOR(); |
| 1754 | + hg_pkg_profile_name=$3; } |
| 1755 | + | PKG_AUTO_SCALING_PROFILE EQUAL error { |
| 1756 | + yyerror("profile name expected"); |
| 1757 | + } |
| 1758 | + | HG_RAM_FLOOR_MB EQUAL NUMBER { IFOR(); |
| 1759 | + hg_ram_floor_mb=$3; } |
| 1760 | + | HG_RAM_FLOOR_MB EQUAL error { |
| 1761 | + yyerror("integer value expected"); |
| 1762 | + } |
| 1763 | + | HG_AUTOSCALE_DRY_RUN EQUAL NUMBER { IFOR(); |
| 1764 | + hg_autoscale_dry_run=$3; } |
| 1765 | + | HG_AUTOSCALE_DRY_RUN EQUAL error { |
| 1766 | + yyerror("integer value expected"); |
| 1767 | + } |
| 1768 | + | SHM_GROW_GRANULE EQUAL scale_size { IFOR(); |
| 1769 | + /* scale_size: positive = MB, negated = KB */ |
| 1770 | + hg_shm_grow_granule = $3 < 0 ? |
| 1771 | + (unsigned long)(-$3) << 10 : |
| 1772 | + (unsigned long)$3 << 20; |
| 1773 | + } |
| 1774 | + | SHM_GROW_GRANULE EQUAL error { |
| 1775 | + yyerror("size expected (number, optional k/m/g)"); |
| 1776 | + } |
| 1777 | + | PKG_GROW_GRANULE EQUAL scale_size { IFOR(); |
| 1778 | + hg_pkg_grow_granule = $3 < 0 ? |
| 1779 | + (unsigned long)(-$3) << 10 : |
| 1780 | + (unsigned long)$3 << 20; |
| 1781 | + } |
| 1782 | + | PKG_GROW_GRANULE EQUAL error { |
| 1783 | + yyerror("size expected (number, optional k/m/g)"); |
| 1784 | + } |
| 1785 | + | HG_LOCK_STALL_US EQUAL NUMBER { IFOR(); |
| 1786 | + hg_lock_stall_us=$3; } |
| 1787 | + | HG_LOCK_STALL_US EQUAL error { |
| 1788 | + yyerror("integer value expected"); |
| 1789 | + } |
| 1790 | + | HG_GROW_AHEAD EQUAL NUMBER { IFOR(); |
| 1791 | + hg_grow_ahead=$3; } |
| 1792 | + | HG_GROW_AHEAD EQUAL error { |
| 1793 | + yyerror("integer value expected"); |
| 1794 | + } |
| 1795 | + | HG_INTERIOR_RELEASE EQUAL NUMBER { IFOR(); |
| 1796 | + hg_interior_release=$3; } |
| 1797 | + | HG_INTERIOR_RELEASE EQUAL error { |
| 1798 | + yyerror("integer value expected"); |
| 1799 | + } |
| 1800 | + | HG_SCALING_CYCLE EQUAL NUMBER { IFOR(); |
| 1801 | + if ($3 < 1) { |
| 1802 | + yyerror("hg_scaling_cycle must be at least 1 second"); |
| 1803 | + YYABORT; |
| 1804 | + } |
| 1805 | + hg_scaling_cycle=$3; } |
| 1806 | + | HG_SCALING_CYCLE EQUAL error { |
| 1807 | + yyerror("integer value expected"); |
| 1808 | + } |
| 1809 | + | HG_SHRINK_STEP EQUAL scale_size { IFOR(); |
| 1810 | + /* scale_size: positive = MB, negated = KB */ |
| 1811 | + hg_shrink_step = $3 < 0 ? |
| 1812 | + (unsigned long)(-$3) << 10 : |
| 1813 | + (unsigned long)$3 << 20; |
| 1814 | + } |
| 1815 | + | HG_SHRINK_STEP EQUAL error { |
| 1816 | + yyerror("size expected (number, optional k/m/g)"); |
| 1817 | + } |
| 1818 | + | HG_MEM_CHECK EQUAL NUMBER { IFOR(); |
| 1819 | + if ($3 < 0 || $3 > 2) { |
| 1820 | + yyerror("hg_mem_check must be 0, 1 or 2"); |
| 1821 | + YYABORT; |
| 1822 | + } |
| 1823 | + hg_mem_check=$3; } |
| 1824 | + | HG_MEM_CHECK EQUAL error { |
| 1825 | + yyerror("integer value expected"); |
| 1826 | + } |
1676 | 1827 | | AUTO_SCALING_CYCLE EQUAL NUMBER { IFOR(); |
1677 | 1828 | auto_scaling_cycle=$3; } |
1678 | 1829 | | AUTO_SCALING_CYCLE EQUAL error { |
|
0 commit comments