Skip to content

Commit

Permalink
Randomize Python backend shared memory region naming (triton-inferenc…
Browse files Browse the repository at this point in the history
…e-server#351)

* Fix deprecated client package

* Randomize Python backend shared memory region naming

* Update docs
  • Loading branch information
Tabrizian authored Apr 8, 2024
1 parent b64b6da commit 4d42111
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1067,11 +1067,13 @@ will create additional threads instead of spawning separate processes.

## Running Multiple Instances of Triton Server

Python backend uses shared memory to transfer requests to the stub process.
When running multiple instances of Triton Server on the same machine that use
Python models, there would be shared memory region name conflicts that can
result in segmentation faults or hangs. In order to avoid this issue, you need
to specify different `shm-region-prefix-name` using the `--backend-config` flag.
Starting from 24.04 release, Python backend uses UUID to generate unique
names for Python backend shared memory regions so that multiple instances of
the server can run at the same time without any conflicts.

If you're using a Python backend released before the 24.04 release, you need
to specify different `shm-region-prefix-name` using the `--backend-config` flag
to avoid conflicts between the shared memory regions. For example:

```
# Triton instance 1
Expand Down
2 changes: 1 addition & 1 deletion examples/preprocessing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import sys

import numpy as np
import tritongrpcclient
import tritonclient.grpc as tritongrpcclient


def load_image(img_path: str):
Expand Down
11 changes: 10 additions & 1 deletion src/pb_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,13 @@ WrapTritonErrorInSharedPtr(TRITONSERVER_Error* error)
return response_error;
}
#endif // NOT TRITON_PB_STUB
}}} // namespace triton::backend::python

std::string
GenerateUUID()
{
static boost::uuids::random_generator generator;
boost::uuids::uuid uuid = generator();
return boost::uuids::to_string(uuid);
}

}}} // namespace triton::backend::python
5 changes: 5 additions & 0 deletions src/pb_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

#include <boost/interprocess/sync/interprocess_condition.hpp>
#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <climits>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -335,4 +338,6 @@ std::shared_ptr<TRITONSERVER_Error*> WrapTritonErrorInSharedPtr(
TRITONSERVER_Error* error);
#endif

std::string GenerateUUID();

}}} // namespace triton::backend::python
1 change: 0 additions & 1 deletion src/python_be.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,6 @@ TRITONBACKEND_Initialize(TRITONBACKEND_Backend* backend)
backend_state->shm_growth_byte_size = 1 * 1024 * 1024; // 1 MB
backend_state->stub_timeout_seconds = 30;
backend_state->shm_message_queue_size = 1000;
backend_state->number_of_instance_inits = 0;
backend_state->thread_pool_size = 32;
// Initialize shared memory region prefix to include backend's name
// to avoid collision between python backend and python-based backends.
Expand Down
5 changes: 1 addition & 4 deletions src/stub_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ StubLauncher::Initialize(ModelState* model_state)
stub_pid_ = 0;
#endif

// Atomically increase and read the stub process count to avoid shared memory
// region name collision
int num_init = ++model_state->StateForBackend()->number_of_instance_inits;
shm_region_name_ =
model_state->StateForBackend()->shared_memory_region_prefix +
std::to_string(num_init);
GenerateUUID();

model_version_ = model_state->Version();

Expand Down

0 comments on commit 4d42111

Please sign in to comment.