Skip to content

Commit 4d42111

Browse files
authored
Randomize Python backend shared memory region naming (triton-inference-server#351)
* Fix deprecated client package * Randomize Python backend shared memory region naming * Update docs
1 parent b64b6da commit 4d42111

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,11 +1067,13 @@ will create additional threads instead of spawning separate processes.
10671067

10681068
## Running Multiple Instances of Triton Server
10691069

1070-
Python backend uses shared memory to transfer requests to the stub process.
1071-
When running multiple instances of Triton Server on the same machine that use
1072-
Python models, there would be shared memory region name conflicts that can
1073-
result in segmentation faults or hangs. In order to avoid this issue, you need
1074-
to specify different `shm-region-prefix-name` using the `--backend-config` flag.
1070+
Starting from 24.04 release, Python backend uses UUID to generate unique
1071+
names for Python backend shared memory regions so that multiple instances of
1072+
the server can run at the same time without any conflicts.
1073+
1074+
If you're using a Python backend released before the 24.04 release, you need
1075+
to specify different `shm-region-prefix-name` using the `--backend-config` flag
1076+
to avoid conflicts between the shared memory regions. For example:
10751077

10761078
```
10771079
# Triton instance 1

examples/preprocessing/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import sys
3030

3131
import numpy as np
32-
import tritongrpcclient
32+
import tritonclient.grpc as tritongrpcclient
3333

3434

3535
def load_image(img_path: str):

src/pb_utils.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,13 @@ WrapTritonErrorInSharedPtr(TRITONSERVER_Error* error)
314314
return response_error;
315315
}
316316
#endif // NOT TRITON_PB_STUB
317-
}}} // namespace triton::backend::python
317+
318+
std::string
319+
GenerateUUID()
320+
{
321+
static boost::uuids::random_generator generator;
322+
boost::uuids::uuid uuid = generator();
323+
return boost::uuids::to_string(uuid);
324+
}
325+
326+
}}} // namespace triton::backend::python

src/pb_utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
#include <boost/interprocess/sync/interprocess_condition.hpp>
3434
#include <boost/interprocess/sync/interprocess_mutex.hpp>
35+
#include <boost/uuid/uuid.hpp>
36+
#include <boost/uuid/uuid_generators.hpp>
37+
#include <boost/uuid/uuid_io.hpp>
3538
#include <climits>
3639
#include <memory>
3740
#include <mutex>
@@ -335,4 +338,6 @@ std::shared_ptr<TRITONSERVER_Error*> WrapTritonErrorInSharedPtr(
335338
TRITONSERVER_Error* error);
336339
#endif
337340

341+
std::string GenerateUUID();
342+
338343
}}} // namespace triton::backend::python

src/python_be.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,6 @@ TRITONBACKEND_Initialize(TRITONBACKEND_Backend* backend)
21312131
backend_state->shm_growth_byte_size = 1 * 1024 * 1024; // 1 MB
21322132
backend_state->stub_timeout_seconds = 30;
21332133
backend_state->shm_message_queue_size = 1000;
2134-
backend_state->number_of_instance_inits = 0;
21352134
backend_state->thread_pool_size = 32;
21362135
// Initialize shared memory region prefix to include backend's name
21372136
// to avoid collision between python backend and python-based backends.

src/stub_launcher.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,9 @@ StubLauncher::Initialize(ModelState* model_state)
7878
stub_pid_ = 0;
7979
#endif
8080

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

8885
model_version_ = model_state->Version();
8986

0 commit comments

Comments
 (0)