Skip to content

Commit f4c0303

Browse files
authored
Merge pull request #6 from triton-inference-server/config-tweaks
- Support credentials from env vars, increase default wait_timeout to 1sec / 1000ms
2 parents 751311c + 3ac04a8 commit f4c0303

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,21 @@ tritonserver --cache-config redis,host=redis-host --cache-config redis,port=6379
9393

9494
| Configuration Option | Required | Description | Default |
9595
|----------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------|---------|
96-
| host | Yes | The hostname or IP address of the server where Redis is running. | N/A |
97-
| port | Yes | The port number to connect to on the server. | N/A |
96+
| host | Yes | The hostname or IP address of the server where Redis is running. | N/A |
97+
| port | Yes | The port number to connect to on the server. | N/A |
9898
| user | No | The username to use for authentication of the ACLs to the Redis Server | default |
99-
| password | No | The password to Redis. | N/A |
100-
| db | No | The db number to user. NOTE - use of the db number is considered an anti-pattern in Redis, so it is advised that you do not use this option | 0 |
101-
| connect_timeout | No | The maximum time, in milliseconds to wait for a connection to be established to Redis. 0 means wait forever | 0 |
102-
| socket_timeout | No | The maximum time, in milliseconds the client will wait for a response from Redis. 0 means wait forever | 0 |
103-
| pool_size | No | The number pooled connections to Redis the client will maintain. | 1 |
104-
| wait_timeout | No | The maximum time, in milliseconds to wait for a connection from the pool. | 100 |
99+
| password | No | The password to Redis. | N/A |
100+
| db | No | The db number to user. NOTE - use of the db number is considered an anti-pattern in Redis, so it is advised that you do not use this option | 0 |
101+
| connect_timeout | No | The maximum time, in milliseconds to wait for a connection to be established to Redis. 0 means wait forever | 0 |
102+
| socket_timeout | No | The maximum time, in milliseconds the client will wait for a response from Redis. 0 means wait forever | 0 |
103+
| pool_size | No | The number pooled connections to Redis the client will maintain. | 1 |
104+
| wait_timeout | No | The maximum time, in milliseconds to wait for a connection from the pool. | 1000 |
105105

106106

107+
### Optional Environment Variables for Credentials
108+
109+
Optionally you may configure your `user`/`password` via environment variables. The corresponding `user` environment variable is `TRITONCACHE_REDIS_USERNAME` whereas the corresponding `password` environment variable is `TRITONCACHE_REDIS_PASSWORD`.
110+
107111
## Monitoring and Observability
108112

109113
There are many ways to go about monitoring what's going on in Redis. One popular mode is to export metrics data from Redis to Prometheus, and use Grafana to observe them.

src/redis_cache.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ setOption(
8989
}
9090
}
9191

92+
void
93+
setOptionFromEnv(const char* envVarName, std::string& option)
94+
{
95+
const char* envVarValue = std::getenv(envVarName);
96+
if (envVarValue != nullptr) {
97+
option = envVarValue;
98+
}
99+
}
100+
92101
TRITONSERVER_Error*
93102
handleError(
94103
const std::string& message, const std::string& key,
@@ -118,6 +127,11 @@ RedisCache::Create(
118127
sw::redis::ConnectionOptions options;
119128
sw::redis::ConnectionPoolOptions poolOptions;
120129

130+
// try pulling user/password from environment fist
131+
// override if present in the config
132+
setOptionFromEnv(USERNAME_ENV_VAR_NAME, options.user);
133+
setOptionFromEnv(PASSWORD_ENV_VAR_NAME, options.password);
134+
121135
setOption("host", options.host, document);
122136
setOption("port", options.port, document);
123137
setOption("user", options.user, document);
@@ -128,7 +142,7 @@ RedisCache::Create(
128142
setOption("pool_size", poolOptions.size, document);
129143
setOption("wait_timeout", poolOptions.wait_timeout, document);
130144
if (!document.HasMember("wait_timeout")) {
131-
poolOptions.wait_timeout = std::chrono::milliseconds(100);
145+
poolOptions.wait_timeout = std::chrono::milliseconds(1000);
132146
}
133147

134148
try {

src/redis_cache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ struct CacheEntry {
4848
// the buffer back to Triton
4949
constexpr uint32_t FIELDS_PER_BUFFER = 4;
5050

51+
constexpr const char* PASSWORD_ENV_VAR_NAME = "TRITONCACHE_REDIS_PASSWORD";
52+
constexpr const char* USERNAME_ENV_VAR_NAME = "TRITONCACHE_REDIS_USERNAME";
53+
54+
5155
#define RETURN_IF_ERROR(X) \
5256
do { \
5357
TRITONSERVER_Error* err__(X); \

0 commit comments

Comments
 (0)