Skip to content

Commit

Permalink
fix #366: support multi-clients in one process
Browse files Browse the repository at this point in the history
  • Loading branch information
barrierye committed Apr 3, 2020
1 parent 4a82a8f commit 94f0f74
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 22 additions & 1 deletion core/sdk-cpp/include/abtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,28 @@ class EndpointRouterBase {
class WeightedRandomRender : public EndpointRouterBase {
public:
static int register_self() {
INLINE_REGIST_OBJECT(WeightedRandomRender, EndpointRouterBase, -1);
// INLINE_REGIST_OBJECT(WeightedRandomRender, EndpointRouterBase, -1);

Factory<WeightedRandomRender, EndpointRouterBase>* factory =
new (std::nothrow) Factory<WeightedRandomRender, EndpointRouterBase>();
if (factory == NULL) {
RAW_LOG_ERROR(
"Failed regist factory: WeightedRandomRender->EndpointRouterBase in "
"macro!");
return -1;
}

// When two clients are created in the same process, two
// "WeightedRandomRender" factory objects are registered.
// But in fact, the two clients can use one factory object
// together.
if (FactoryPool<EndpointRouterBase>::instance().register_factory(
"WeightedRandomRender", factory) != 0) {
RAW_LOG_INFO(
"Factory has been registed: "
"WeightedRandomRender->EndpointRouterBase.");
}

return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion python/paddle_serving_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def connect(self, endpoints=None):
)
else:
if self.predictor_sdk_ is None:
self.add_variant('var1', endpoints, 100)
timestamp = time.time()
self.add_variant('default_tag_{}'.format(timestamp), endpoints,
100)
else:
print(
"parameter endpoints({}) will not take effect, because you use the add_variant function.".
Expand Down

0 comments on commit 94f0f74

Please sign in to comment.