Giter Site home page Giter Site logo

redis_cache's Introduction

License

Triton Redis Cache

This repo contains an example cache for caching data with Redis.

Ask questions or report problems in the main Triton issues page.

Build the Cache

If you don't have it installed already - install rapidjson-dev:

apt install rapidjson-dev

Use a recent cmake to build and run the following:

$ mkdir build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=`pwd`/install ..
$ make install

The following required Triton repositories will be pulled and used in the build. By default the "main" branch/tag will be used for each repo but the following CMake arguments can be used to override.

  • triton-inference-server/core: -D TRITON_CORE_REPO_TAG=[tag]
  • triton-inference-server/common: -D TRITON_COMMON_REPO_TAG=[tag]

Using the Cache

Deploying to Triton

In order for the Redis Cache to be deployed to triton, you must build the binary (see build instructions), and copy the libtritoncache_redis.so file to the folder redis in the cache directory on the server you are running triton from, by default this will be /opt/tritonserver/caches - but this can be adjusted by use of the --cache-dir CLI option as needed.

It is also required that Redis be running on a system reachable by Triton. There are many ways to deploy Redis, to learn how to get started with Redis look at Redis's getting started guide.

Configuration

The cache is configured by the using --cache-config CLI options. The --cache-config option is variadic, meaning it can be repeated multiple times to set multiple configuration fields. The format of a --cache-config option is <cache_name>,<key>=<value>. At a minimum you must provide a host and port to allow the client to connect to Redis e.g. let's try connecting to a redis instance living on the host redis-host and listening on port 6379:

tritonserver --cache-config redis,host=redis-host --cache-config redis,port=6379

Available Configuration Options

Configuration Option Required Description Default
host Yes The hostname or IP address of the server where Redis is running. N/A
port Yes The port number to connect to on the server. N/A
user No The username to use for authentication of the ACLs to the Redis Server default
password No The password to Redis. N/A
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
connect_timeout No The maximum time, in milliseconds to wait for a connection to be established to Redis. 0 means wait forever 0
socket_timeout No The maximum time, in milliseconds the client will wait for a response from Redis. 0 means wait forever 0
pool_size No The number pooled connections to Redis the client will maintain. 1
wait_timeout No The maximum time, in milliseconds to wait for a connection from the pool. 1000

Optional Environment Variables for Credentials

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.

TLS

Transport Layer Security (TLS) can be enabled in Redis and within the Triton Redis Cache, to do so you will need a TLS enabled version of Redis, e.g. OSS Redis or Redis Enterprise. You will also need to configure Triton Server to use TLS with Redis through the following --cache-config TLS options.

Configuration Items for TLS

Configuration Option Required Description
tls_enabled Yes set to true to enable TLS
cert no The certificate to use for TLS.
key no The certificate key to use for TLS.
cacert No The Certificate Authority certificate to use for TLS.
sni No Server name indication for TLS.

Monitoring and Observability

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.

Example

You can try out the Redis Cache with Triton in docker:

  • clone this repo: git clone https://github.com/triton-inference-server/redis_cache
  • follow build instructions enumerated above
  • clone the Triton server repo: git clone https://github.com/triton-inference-server
  • Add the following to: docs/examples/model_repository/densenet_onnx/config.pbtxt
response_cache{
  enable:true
}
docker login nvcr.io

Username: $oauthtoken
Password: <MY API KEY>

NOTE: Username: $oauthtoken in this context means that your username is literally $oauthtoken - your API key serves as the unique part of your credentials

  • run docker-compose build
  • run docker-compose up
  • In a separate terminal run docker run -it --rm --net=host nvcr.io/nvidia/tritonserver:23.06-py3-sdk
  • Run /workspace/install/bin/image_client -m densenet_onnx -c 3 -s INCEPTION /workspace/images/mug.jpg
    • on the first run - this will miss the cache
    • subsequent runs will pull the inference out of the cache
    • you can validate this by watching Redis with docker exec -it redis_cache_triton-redis_1 redis-cli monitor

redis_cache's People

Contributors

dyastremsky avatar nv-kmcgill53 avatar rmccorm4 avatar slorello89 avatar spartee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

redis_cache's Issues

CMake Error at CMakeLists.txt:76 (find_library): Could not find REDISPP using the following names: redis++

Hi.
I tried to follow the instructions to build the binary, but I got error saying Could not find REDISPP using the following names: redis++" when running cmake -DCMAKE_INSTALL_PREFIX:PATH=pwd/install .. Is there anyone who could provide some tips to address this issue?

Here is the full compiled logs.

ubuntu@master://home/ubuntu/redis_cache/build$ cmake -DCMAKE_INCLUDE_PATH=~`pwd`/install/include -DCMAKE_LIBRARY_PATH=~`pwd`/install/lib -DCMAKE_INSTALL_PREFIX:PATH=`pwd`/install ..
-- RapidJSON found. Headers: /usr/include
-- RapidJSON found. Headers: /usr/include
Hiredis has already been installed
mkdir: cannot create directory ‘compile’: File exists
-- redis-plus-plus version: 1.3.1
-- redis-plus-plus build type: Release
-- redis-plus-plus build with CXX standard: c++17
-- redis-plus-plus TLS support: ON
-- redis-plus-plus build static library: ON
-- redis-plus-plus build static library with position independent code: ON
-- redis-plus-plus build shared library: OFF
-- redis-plus-plus build test: OFF
-- Debian package name: .deb
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/redis_cache/third-party/redis-plus-plus/compile
Consolidate compiler generated dependencies of target redis++_static
[  5%] Building CXX object CMakeFiles/redis++_static.dir/src/sw/redis++/command.cpp.o
[ 11%] Building CXX object CMakeFiles/redis++_static.dir/src/sw/redis++/connection.cpp.o
[ 17%] Building CXX object CMakeFiles/redis++_static.dir/src/sw/redis++/connection_pool.cpp.o
[ 23%] Building CXX object CMakeFiles/redis++_static.dir/src/sw/redis++/pipeline.cpp.o
In file included from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/connection.h:31,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/pipeline.h:22,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/pipeline.cpp:17:
/home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/tls/tls.h:23:10: fatal error: hiredis/hiredis_ssl.h: No such file or directory
   23 | #include <hiredis/hiredis_ssl.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
In file included from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/connection.h:31,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/connection.cpp:17:
/home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/tls/tls.h:23:10: fatal error: hiredis/hiredis_ssl.h: No such file or directory
   23 | #include <hiredis/hiredis_ssl.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/redis++_static.dir/build.make:160: CMakeFiles/redis++_static.dir/src/sw/redis++/pipeline.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/connection.h:31,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/command.h:24,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/command.cpp:17:
/home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/tls/tls.h:23:10: fatal error: hiredis/hiredis_ssl.h: No such file or directory
   23 | #include <hiredis/hiredis_ssl.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
In file included from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/connection.h:31,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/connection_pool.h:26,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/connection_pool.cpp:17:
/home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/tls/tls.h:23:10: fatal error: hiredis/hiredis_ssl.h: No such file or directory
   23 | #include <hiredis/hiredis_ssl.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/redis++_static.dir/build.make:104: CMakeFiles/redis++_static.dir/src/sw/redis++/connection.cpp.o] Error 1
make[2]: *** [CMakeFiles/redis++_static.dir/build.make:118: CMakeFiles/redis++_static.dir/src/sw/redis++/connection_pool.cpp.o] Error 1
make[2]: *** [CMakeFiles/redis++_static.dir/build.make:76: CMakeFiles/redis++_static.dir/src/sw/redis++/command.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/redis++_static.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
[  5%] Building CXX object CMakeFiles/redis++_static.dir/src/sw/redis++/command.cpp.o
In file included from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/connection.h:31,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/command.h:24,
                 from /home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/command.cpp:17:
/home/ubuntu/redis_cache/third-party/redis-plus-plus/src/sw/redis++/tls/tls.h:23:10: fatal error: hiredis/hiredis_ssl.h: No such file or directory
   23 | #include <hiredis/hiredis_ssl.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/redis++_static.dir/build.make:76: CMakeFiles/redis++_static.dir/src/sw/redis++/command.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/redis++_static.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
Finished installing Redis-plus-plus
CMake Error at CMakeLists.txt:76 (find_library):
  Could not find REDISPP using the following names: redis++


-- Configuring incomplete, errors occurred!
See also "//home/ubuntu/redis_cache/build/CMakeFiles/CMakeOutput.log".

I'm sure that both files (hiredis.h and hiredis_ssl.h) are created as follows

ubuntu@master:~/redis_cache/build$ cd /home/ubuntu/redis_cache/build/install/include/hiredis
ubuntu@master:~/redis_cache/build/install/include/hiredis$ ls -l
total 60
drwx------ 2 ubuntu ubuntu  4096 Jul  2 11:31 adapters
-rw------- 1 ubuntu ubuntu  2982 Jul  2 05:05 alloc.h
-rw------- 1 ubuntu ubuntu  6027 Jul  2 05:05 async.h
-rw------- 1 ubuntu ubuntu 12747 Jul  2 05:05 hiredis.h
-rw------- 1 ubuntu ubuntu  4615 Jul  2 05:05 hiredis_ssl.h
-rw------- 1 ubuntu ubuntu  4918 Jul  2 05:05 read.h
-rw------- 1 ubuntu ubuntu  9213 Jul  2 05:05 sds.h

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.