Skip to content

Commit d238a56

Browse files
committed
Merge commit for internal changes
2 parents b849867 + 06e22f9 commit d238a56

21 files changed

+503
-102
lines changed

tensorflow_serving/batching/BUILD

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ cc_library(
5353
deps = [
5454
"@tf//tensorflow/core:lib",
5555
":batch_scheduler",
56-
":retrier",
56+
":batch_scheduler_retrier",
5757
"//tensorflow_serving/util:optional",
5858
],
5959
)
@@ -74,8 +74,8 @@ cc_test(
7474
)
7575

7676
cc_library(
77-
name = "retrier",
78-
hdrs = ["retrier.h"],
77+
name = "batch_scheduler_retrier",
78+
hdrs = ["batch_scheduler_retrier.h"],
7979
visibility = ["//visibility:public"],
8080
deps = [
8181
"@tf//tensorflow/core:lib",
@@ -84,15 +84,15 @@ cc_library(
8484
)
8585

8686
cc_test(
87-
name = "retrier_test",
87+
name = "batch_scheduler_retrier_test",
8888
srcs = [
89-
"retrier_test.cc",
89+
"batch_scheduler_retrier_test.cc",
9090
],
9191
deps = [
9292
"@tf//tensorflow/core:lib",
9393
"@tf//tensorflow/core:protos_all_cc",
9494
"@tf//tensorflow/core:test",
95-
":retrier",
95+
":batch_scheduler_retrier",
9696
"//tensorflow_serving/core/test_util:test_main",
9797
"//tensorflow_serving/test_util:fake_clock_env",
9898
],

tensorflow_serving/batching/batch_scheduler.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
// Abstractions for processing small tasks in a batched fashion, to reduce
1717
// processing times and costs that can be amortized across multiple tasks.
1818
//
19-
// The core class is BatchScheduler, which groups Tasks into Batches.
19+
// The core class is BatchScheduler, which groups tasks into batches.
2020
//
2121
// BatchScheduler encapsulates logic for aggregating multiple tasks into a
2222
// batch, and kicking off processing of a batch on a thread pool it manages.
@@ -42,7 +42,6 @@ limitations under the License.
4242

4343
namespace tensorflow {
4444
namespace serving {
45-
namespace batching {
4645

4746
// The abstract superclass for a unit of work to be done as part of a batch.
4847
//
@@ -53,26 +52,27 @@ namespace batching {
5352
// (d) a place to store the output data, upon success.
5453
//
5554
// Items (b), (c) and (d) are typically non-owned pointers to data homed
56-
// elsewhere, because a Task's ownership gets transferred to a BatchScheduler
55+
// elsewhere, because a task's ownership gets transferred to a BatchScheduler
5756
// (see below) and it may be deleted as soon as it is done executing.
58-
class Task {
57+
class BatchTask {
5958
public:
60-
virtual ~Task() = default;
59+
virtual ~BatchTask() = default;
6160

6261
// Returns the size of the task, in terms of how much it contributes to the
6362
// size of a batch. (A batch's size is the sum of its task sizes.)
6463
virtual size_t size() const = 0;
6564
};
6665

67-
// A thread-safe collection of Tasks, to be executed together in some fashion.
66+
// A thread-safe collection of BatchTasks, to be executed together in some
67+
// fashion.
6868
//
6969
// At a given time, a batch is either "open" or "closed": an open batch can
7070
// accept new tasks; a closed one cannot. A batch is monotonic: initially it is
7171
// open and tasks can be added to it; then it is closed and its set of tasks
7272
// remains fixed for the remainder of its life. A closed batch cannot be re-
7373
// opened. Tasks can never be removed from a batch.
7474
//
75-
// Type parameter TaskType must be a subclass of Task.
75+
// Type parameter TaskType must be a subclass of BatchTask.
7676
template <typename TaskType>
7777
class Batch {
7878
public:
@@ -127,7 +127,7 @@ class Batch {
127127
// and processes each batch on a pool of "batch threads" that it manages. The
128128
// actual logic for processing a batch is accomplished via a callback.
129129
//
130-
// Type parameter TaskType must be a subclass of Task.
130+
// Type parameter TaskType must be a subclass of BatchTask.
131131
template <typename TaskType>
132132
class BatchScheduler {
133133
public:
@@ -252,7 +252,6 @@ void Batch<TaskType>::Close() {
252252
closed_.Notify();
253253
}
254254

255-
} // namespace batching
256255
} // namespace serving
257256
} // namespace tensorflow
258257

tensorflow_serving/batching/retrier.h renamed to tensorflow_serving/batching/batch_scheduler_retrier.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
#ifndef TENSORFLOW_SERVING_BATCHING_RETRIER_H_
17-
#define TENSORFLOW_SERVING_BATCHING_RETRIER_H_
16+
#ifndef TENSORFLOW_SERVING_BATCHING_BATCH_SCHEDULER_RETRIER_H_
17+
#define TENSORFLOW_SERVING_BATCHING_BATCH_SCHEDULER_RETRIER_H_
1818

1919
#include <stddef.h>
2020
#include <cstddef>
@@ -27,14 +27,13 @@ limitations under the License.
2727

2828
namespace tensorflow {
2929
namespace serving {
30-
namespace batching {
3130

3231
// A wrapper around another BatchScheduler that automatically retries
3332
// Schedule() requests. Returns an UNAVAILABLE error only after retry attempts
3433
// have failed (based on parameters that govern the maximum number of retries
3534
// and the retry time interval).
3635
template <typename TaskType>
37-
class Retrier : public BatchScheduler<TaskType> {
36+
class BatchSchedulerRetrier : public BatchScheduler<TaskType> {
3837
public:
3938
struct Options {
4039
// The maximum amount of time to spend retrying 'wrapped_->Schedule()'
@@ -47,33 +46,33 @@ class Retrier : public BatchScheduler<TaskType> {
4746
// The environment to use for time and sleeping.
4847
Env* env = Env::Default();
4948
};
50-
static Status Create(const Options& options,
51-
std::unique_ptr<BatchScheduler<TaskType>> wrapped,
52-
std::unique_ptr<Retrier<TaskType>>* result);
49+
static Status Create(
50+
const Options& options, std::unique_ptr<BatchScheduler<TaskType>> wrapped,
51+
std::unique_ptr<BatchSchedulerRetrier<TaskType>>* result);
5352

54-
~Retrier() override = default;
53+
~BatchSchedulerRetrier() override = default;
5554

5655
Status Schedule(std::unique_ptr<TaskType>* task) override;
5756
size_t NumEnqueuedTasks() const override;
5857
size_t SchedulingCapacity() const override;
5958

6059
private:
61-
Retrier(const Options& options,
62-
std::unique_ptr<BatchScheduler<TaskType>> wrapped);
60+
BatchSchedulerRetrier(const Options& options,
61+
std::unique_ptr<BatchScheduler<TaskType>> wrapped);
6362

6463
const Options options_;
6564
std::unique_ptr<BatchScheduler<TaskType>> wrapped_;
6665

67-
TF_DISALLOW_COPY_AND_ASSIGN(Retrier);
66+
TF_DISALLOW_COPY_AND_ASSIGN(BatchSchedulerRetrier);
6867
};
6968

7069
//////////
7170
// Implementation details follow. API users need not read.
7271

7372
template <typename TaskType>
74-
Status Retrier<TaskType>::Create(
73+
Status BatchSchedulerRetrier<TaskType>::Create(
7574
const Options& options, std::unique_ptr<BatchScheduler<TaskType>> wrapped,
76-
std::unique_ptr<Retrier<TaskType>>* result) {
75+
std::unique_ptr<BatchSchedulerRetrier<TaskType>>* result) {
7776
if (options.max_time_micros < 0) {
7877
return errors::InvalidArgument("max_time_micros must be non-negative; was ",
7978
options.max_time_micros);
@@ -83,12 +82,13 @@ Status Retrier<TaskType>::Create(
8382
"retry_delay_micros must be non-negative; was ",
8483
options.retry_delay_micros);
8584
}
86-
result->reset(new Retrier(options, std::move(wrapped)));
85+
result->reset(new BatchSchedulerRetrier(options, std::move(wrapped)));
8786
return Status::OK();
8887
}
8988

9089
template <typename TaskType>
91-
Status Retrier<TaskType>::Schedule(std::unique_ptr<TaskType>* task) {
90+
Status BatchSchedulerRetrier<TaskType>::Schedule(
91+
std::unique_ptr<TaskType>* task) {
9292
Status status;
9393

9494
const uint64 start_time_micros = options_.env->NowMicros();
@@ -112,22 +112,21 @@ Status Retrier<TaskType>::Schedule(std::unique_ptr<TaskType>* task) {
112112
}
113113

114114
template <typename TaskType>
115-
size_t Retrier<TaskType>::NumEnqueuedTasks() const {
115+
size_t BatchSchedulerRetrier<TaskType>::NumEnqueuedTasks() const {
116116
return wrapped_->NumEnqueuedTasks();
117117
}
118118

119119
template <typename TaskType>
120-
size_t Retrier<TaskType>::SchedulingCapacity() const {
120+
size_t BatchSchedulerRetrier<TaskType>::SchedulingCapacity() const {
121121
return wrapped_->SchedulingCapacity();
122122
}
123123

124124
template <typename TaskType>
125-
Retrier<TaskType>::Retrier(const Options& options,
126-
std::unique_ptr<BatchScheduler<TaskType>> wrapped)
125+
BatchSchedulerRetrier<TaskType>::BatchSchedulerRetrier(
126+
const Options& options, std::unique_ptr<BatchScheduler<TaskType>> wrapped)
127127
: options_(options), wrapped_(std::move(wrapped)) {}
128128

129-
} // namespace batching
130129
} // namespace serving
131130
} // namespace tensorflow
132131

133-
#endif // TENSORFLOW_SERVING_BATCHING_RETRIER_H_
132+
#endif // TENSORFLOW_SERVING_BATCHING_BATCH_SCHEDULER_RETRIER_H_

tensorflow_serving/batching/retrier_test.cc renamed to tensorflow_serving/batching/batch_scheduler_retrier_test.cc

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
#include "tensorflow_serving/batching/retrier.h"
16+
#include "tensorflow_serving/batching/batch_scheduler_retrier.h"
1717

1818
#include <algorithm>
1919
#include <limits>
@@ -29,10 +29,9 @@ limitations under the License.
2929

3030
namespace tensorflow {
3131
namespace serving {
32-
namespace batching {
3332
namespace {
3433

35-
class FakeTask : public Task {
34+
class FakeTask : public BatchTask {
3635
public:
3736
FakeTask() = default;
3837
~FakeTask() override = default;
@@ -101,23 +100,23 @@ class StubbornScheduler : public BatchScheduler<FakeTask> {
101100
TF_DISALLOW_COPY_AND_ASSIGN(StubbornScheduler);
102101
};
103102

104-
TEST(RetrierTest, ConstMethodsForwardToWrappedScheduler) {
103+
TEST(BatchSchedulerRetrierTest, ConstMethodsForwardToWrappedScheduler) {
105104
auto broken_scheduler = std::unique_ptr<BrokenScheduler>(new BrokenScheduler);
106-
Retrier<FakeTask>::Options options;
107-
std::unique_ptr<Retrier<FakeTask>> retrier;
108-
TF_CHECK_OK(Retrier<FakeTask>::Create(options, std::move(broken_scheduler),
109-
&retrier));
105+
BatchSchedulerRetrier<FakeTask>::Options options;
106+
std::unique_ptr<BatchSchedulerRetrier<FakeTask>> retrier;
107+
TF_CHECK_OK(BatchSchedulerRetrier<FakeTask>::Create(
108+
options, std::move(broken_scheduler), &retrier));
110109
EXPECT_EQ(7, retrier->NumEnqueuedTasks());
111110
EXPECT_EQ(42, retrier->SchedulingCapacity());
112111
}
113112

114-
TEST(RetrierTest, PermanentFailure) {
113+
TEST(BatchSchedulerRetrierTest, PermanentFailure) {
115114
auto broken_scheduler = std::unique_ptr<BrokenScheduler>(new BrokenScheduler);
116115
auto broken_scheduler_ptr = broken_scheduler.get();
117-
Retrier<FakeTask>::Options options;
118-
std::unique_ptr<Retrier<FakeTask>> retrier;
119-
TF_CHECK_OK(Retrier<FakeTask>::Create(options, std::move(broken_scheduler),
120-
&retrier));
116+
BatchSchedulerRetrier<FakeTask>::Options options;
117+
std::unique_ptr<BatchSchedulerRetrier<FakeTask>> retrier;
118+
TF_CHECK_OK(BatchSchedulerRetrier<FakeTask>::Create(
119+
options, std::move(broken_scheduler), &retrier));
121120
auto task = std::unique_ptr<FakeTask>(new FakeTask);
122121
Status status = retrier->Schedule(&task);
123122
ASSERT_FALSE(status.ok());
@@ -126,7 +125,7 @@ TEST(RetrierTest, PermanentFailure) {
126125
EXPECT_EQ(1, broken_scheduler_ptr->num_submit_calls());
127126
}
128127

129-
TEST(RetrierTest, MaxTime) {
128+
TEST(BatchSchedulerRetrierTest, MaxTime) {
130129
for (int num_attempts_to_succeed = 1; num_attempts_to_succeed < 3;
131130
++num_attempts_to_succeed) {
132131
for (int max_attempts = 1; max_attempts < 5; ++max_attempts) {
@@ -135,12 +134,12 @@ TEST(RetrierTest, MaxTime) {
135134
auto stubborn_scheduler = std::unique_ptr<StubbornScheduler>(
136135
new StubbornScheduler(num_attempts_to_succeed));
137136
auto stubborn_scheduler_ptr = stubborn_scheduler.get();
138-
Retrier<FakeTask>::Options options;
137+
BatchSchedulerRetrier<FakeTask>::Options options;
139138
options.retry_delay_micros = 1;
140139
options.max_time_micros = max_attempts;
141140
options.env = &env;
142-
std::unique_ptr<Retrier<FakeTask>> retrier;
143-
TF_CHECK_OK(Retrier<FakeTask>::Create(
141+
std::unique_ptr<BatchSchedulerRetrier<FakeTask>> retrier;
142+
TF_CHECK_OK(BatchSchedulerRetrier<FakeTask>::Create(
144143
options, std::move(stubborn_scheduler), &retrier));
145144

146145
const bool expect_success = max_attempts >= num_attempts_to_succeed;
@@ -171,20 +170,20 @@ TEST(RetrierTest, MaxTime) {
171170
}
172171
}
173172

174-
TEST(RetrierTest, RetryDelay) {
173+
TEST(BatchSchedulerRetrierTest, RetryDelay) {
175174
test_util::FakeClockEnv env(Env::Default());
176175

177176
const int num_attempts_to_succeed = 3;
178177
auto stubborn_scheduler = std::unique_ptr<StubbornScheduler>(
179178
new StubbornScheduler(num_attempts_to_succeed));
180179
auto stubborn_scheduler_ptr = stubborn_scheduler.get();
181-
Retrier<FakeTask>::Options options;
180+
BatchSchedulerRetrier<FakeTask>::Options options;
182181
options.retry_delay_micros = 7;
183182
options.max_time_micros = 100;
184183
options.env = &env;
185-
std::unique_ptr<Retrier<FakeTask>> retrier;
186-
TF_CHECK_OK(Retrier<FakeTask>::Create(options, std::move(stubborn_scheduler),
187-
&retrier));
184+
std::unique_ptr<BatchSchedulerRetrier<FakeTask>> retrier;
185+
TF_CHECK_OK(BatchSchedulerRetrier<FakeTask>::Create(
186+
options, std::move(stubborn_scheduler), &retrier));
188187

189188
Notification done;
190189
std::unique_ptr<Thread> run_retrier(Env::Default()->StartThread(
@@ -205,6 +204,5 @@ TEST(RetrierTest, RetryDelay) {
205204
}
206205

207206
} // namespace
208-
} // namespace batching
209207
} // namespace serving
210208
} // namespace tensorflow

tensorflow_serving/batching/batch_scheduler_test.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ limitations under the License.
2121

2222
namespace tensorflow {
2323
namespace serving {
24-
namespace batching {
2524

2625
namespace {
2726

28-
class FakeTask : public Task {
27+
class FakeTask : public BatchTask {
2928
public:
3029
explicit FakeTask(size_t size) : size_(size) {}
3130

@@ -111,6 +110,5 @@ TEST(BatchTest, DeletionBlocksUntilClosed) {
111110
deleted.WaitForNotification();
112111
}
113112

114-
} // namespace batching
115113
} // namespace serving
116114
} // namespace tensorflow

tensorflow_serving/batching/streaming_batch_scheduler.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717

1818
namespace tensorflow {
1919
namespace serving {
20-
namespace batching {
2120

2221
namespace internal {
2322

@@ -86,6 +85,5 @@ void SingleTaskScheduler::ThreadLogic() {
8685

8786
} // namespace internal
8887

89-
} // namespace batching
9088
} // namespace serving
9189
} // namespace tensorflow

0 commit comments

Comments
 (0)