Skip to content

Commit cba8b22

Browse files
committed
Allows for resizing librecords via command line option
This also eliminates the old configure option --with-max-api-stats. Rather, you should set the full size of the entire librecords with this setting, with ~1100 needed for the core, and (recommended) 500 for metrics as a minimum. That is the default (1600) unless specified. The reason this has to be a command line is because librecords can not be initialized without it, hence, it can not be a records.config setting.
1 parent f95d7be commit cba8b22

File tree

13 files changed

+42
-21
lines changed

13 files changed

+42
-21
lines changed

doc/appendices/command-line/traffic_manager.en.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Description
4040
.. option:: --proxyPort PORT
4141
.. option:: --recordsConf FILE
4242
.. option:: --tsArgs ARGUMENTS
43+
.. option:: --maxRecords RECORDS
4344
.. option:: --version
4445

4546
Signals

doc/appendices/command-line/traffic_server.en.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ the available tests.
8383

8484
.. option:: -t MSECS, --poll_timeout MSECS
8585

86+
.. option:: -m RECORDS, --maxRecords RECORDS
87+
8688
.. option:: -h, --help
8789

8890
Print usage information and exit.

include/tscore/ink_config.h.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@
9292

9393
#define TS_MAX_HOST_NAME_LEN @max_host_name_len@
9494

95-
#define TS_MAX_API_STATS @max_api_stats@
96-
9795
#define SPLIT_DNS 1
9896

9997
/* Defaults for user / group */

lib/records/P_RecDefs.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131

3232
#define REC_MESSAGE_ELE_MAGIC 0xF00DF00D
3333

34-
// This is for the internal stats and configs, as well as API stats. We currently use
35-
// about 1600 stats + configs for the core, but we're allocating 2000 for some growth.
36-
// TODO: if/when we switch to a new config system, we should make this run-time dynamic.
37-
#define REC_MAX_RECORDS (2000 + TS_MAX_API_STATS)
34+
// We need at least this many internal record entries for our configurations and metrics. Any
35+
// additional slots in librecords will be allocated to the plugin metrics. These should be
36+
// updated if we change the internal librecords size significantly.
37+
#define REC_INTERNAL_RECORDS 1100
38+
#define REC_MIN_API_RECORDS 500
3839

3940
#define REC_CONFIG_UPDATE_INTERVAL_MS 3000
4041
#define REC_REMOTE_SYNC_INTERVAL_MS 5000

lib/records/RecCore.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@
2525
#include "tscore/ink_memory.h"
2626
#include "tscore/ink_string.h"
2727

28+
#include "RecordsConfig.h"
2829
#include "P_RecFile.h"
2930
#include "P_RecCore.h"
3031
#include "P_RecUtils.h"
3132
#include "tscore/I_Layout.h"
3233

34+
// This is needed to manage the size of the librecords record. It can't be static, because it needs to be modified
35+
// and used (read) from several binaries / modules.
36+
int max_records_entries = REC_INTERNAL_RECORDS + REC_MIN_API_RECORDS;
37+
3338
static bool g_initialized = false;
3439

3540
RecRecord *g_records = nullptr;
@@ -197,7 +202,7 @@ RecCoreInit(RecModeT mode_type, Diags *_diags)
197202
g_num_records = 0;
198203

199204
// initialize record array for our internal stats (this can be reallocated later)
200-
g_records = (RecRecord *)ats_malloc(REC_MAX_RECORDS * sizeof(RecRecord));
205+
g_records = (RecRecord *)ats_malloc(max_records_entries * sizeof(RecRecord));
201206

202207
// initialize record rwlock
203208
ink_rwlock_init(&g_records_rwlock);

lib/records/RecUtils.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "tscore/ink_platform.h"
2525
#include "tscore/ink_memory.h"
2626
#include "tscore/ParseRules.h"
27+
#include "RecordsConfig.h"
2728
#include "P_RecUtils.h"
2829
#include "P_RecCore.h"
2930

@@ -49,8 +50,8 @@ RecRecordFree(RecRecord *r)
4950
RecRecord *
5051
RecAlloc(RecT rec_type, const char *name, RecDataT data_type)
5152
{
52-
if (g_num_records >= REC_MAX_RECORDS) {
53-
Warning("too many stats/configs, please increase REC_MAX_RECORDS or rebuild with --with_max_api_stats=<n>");
53+
if (g_num_records >= max_records_entries) {
54+
Warning("too many stats/configs, please increase max_records_entries using the --maxRecords command line option");
5455
return nullptr;
5556
}
5657

mgmt/RecordsConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
#include "records/P_RecCore.h"
2727

28+
// This is to manage the librecords table sizes. Not awesome, but better than the earlier recompiling of ATS requirement...
29+
extern int max_records_entries;
30+
2831
enum RecordRequiredType {
2932
RR_NULL, // config is _not_ required to be defined in records.config
3033
RR_REQUIRED // config _is_ required to be defined in record.config

mgmt/api/CoreAPI.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
*
2929
*
3030
***************************************************************************/
31+
#include <vector>
3132

3233
#include "tscore/ink_platform.h"
3334
#include "tscore/ink_file.h"
3435
#include "tscore/ParseRules.h"
36+
#include "RecordsConfig.h"
3537
#include "Alarms.h"
3638
#include "MgmtUtils.h"
3739
#include "LocalManager.h"
@@ -47,8 +49,6 @@
4749
#include "tscore/I_Layout.h"
4850
#include "tscore/ink_cap.h"
4951

50-
#include <vector>
51-
5252
// global variable
5353
static CallbackTable *local_event_callbacks;
5454

@@ -170,7 +170,11 @@ ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
170170

171171
// Start with the default options from records.config.
172172
if (RecGetRecordString_Xmalloc("proxy.config.proxy_binary_opts", &proxy_options) == REC_ERR_OKAY) {
173-
snprintf(tsArgs, sizeof(tsArgs), "%s", proxy_options);
173+
if (max_records_entries == (REC_INTERNAL_RECORDS + REC_MIN_API_RECORDS)) { // Default size, don't need to pass down to _server
174+
snprintf(tsArgs, sizeof(tsArgs), "%s", proxy_options);
175+
} else {
176+
snprintf(tsArgs, sizeof(tsArgs), "%s --maxRecords %d", proxy_options, max_records_entries);
177+
}
174178
ats_free(proxy_options);
175179
}
176180

plugins/experimental/remap_stats/remap_stats.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ typedef struct {
4242
TSMutex stat_creation_mutex;
4343
} config_t;
4444

45+
// From "core".... sigh, but we need it for now at least.
46+
extern int max_records_entries;
47+
4548
static void
4649
stat_add(char *name, TSMgmtInt amount, TSStatPersistence persist_type, TSMutex create_mutex)
4750
{
@@ -52,7 +55,7 @@ stat_add(char *name, TSMgmtInt amount, TSStatPersistence persist_type, TSMutex c
5255

5356
if (unlikely(!hash_init)) {
5457
// NOLINTNEXTLINE
55-
hcreate_r(TS_MAX_API_STATS << 1, &stat_cache);
58+
hcreate_r(max_records_entries << 1, &stat_cache); // This is weird, but oh well.
5659
hash_init = true;
5760
TSDebug(DEBUG_TAG, "stat cache hash init");
5861
}

src/traffic_layout/info.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ produce_features(bool json)
116116
print_feature("TS_MAX_THREADS_IN_EACH_THREAD_TYPE", TS_MAX_THREADS_IN_EACH_THREAD_TYPE, json);
117117
print_feature("TS_MAX_NUMBER_EVENT_THREADS", TS_MAX_NUMBER_EVENT_THREADS, json);
118118
print_feature("TS_MAX_HOST_NAME_LEN", TS_MAX_HOST_NAME_LEN, json);
119-
print_feature("TS_MAX_API_STATS", TS_MAX_API_STATS, json);
120119
print_feature("SPLIT_DNS", SPLIT_DNS, json);
121120
print_feature("TS_PKGSYSUSER", TS_PKGSYSUSER, json);
122121
print_feature("TS_PKGSYSGROUP", TS_PKGSYSGROUP, json, true);

0 commit comments

Comments
 (0)