Merge branch 'master' of https://github.com/grpc/grpc into yapf-tools

pull/13719/head
ncteisen 7 years ago
commit c47c58971b
  1. 1
      .github/CODEOWNERS
  2. 1
      examples/python/helloworld/greeter_client.py
  3. 2
      examples/python/helloworld/greeter_server.py
  4. 8
      examples/python/multiplex/multiplex_client.py
  5. 23
      examples/python/multiplex/multiplex_server.py
  6. 1
      examples/python/multiplex/route_guide_resources.py
  7. 23
      examples/python/multiplex/run_codegen.py
  8. 7
      examples/python/route_guide/route_guide_client.py
  9. 1
      examples/python/route_guide/route_guide_resources.py
  10. 19
      examples/python/route_guide/route_guide_server.py
  11. 12
      examples/python/route_guide/run_codegen.py
  12. 2
      src/core/lib/iomgr/ev_epoll1_linux.cc
  13. 8
      src/core/lib/iomgr/ev_poll_posix.cc
  14. 2
      src/core/lib/iomgr/executor.cc
  15. 2
      src/core/lib/iomgr/iomgr.cc
  16. 4
      src/core/lib/iomgr/timer_manager.cc
  17. 11
      src/core/lib/support/sync_posix.cc
  18. 2
      src/core/lib/surface/completion_queue.cc
  19. 2
      src/core/lib/surface/server.cc
  20. 2
      test/core/support/cpu_test.cc
  21. 12
      test/core/support/sync_test.cc
  22. 4
      test/cpp/util/cli_call.cc
  23. 2
      tools/distrib/yapf_code.sh
  24. 9
      tools/run_tests/performance/OWNERS

@ -4,3 +4,4 @@
/**/OWNERS @markdroth @nicolasnoble @ctiller
/bazel/** @nicolasnoble @dgquintas @ctiller
/src/core/ext/filters/client_channel/** @markdroth @dgquintas @ctiller
/tools/run_tests/performance/** @ncteisen @matt-kwong @ctiller

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Python implementation of the GRPC helloworld.Greeter client."""
from __future__ import print_function

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Python implementation of the GRPC helloworld.Greeter server."""
from concurrent import futures
@ -42,5 +41,6 @@ def serve():
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A client that makes both Greeter and RouteGuide RPCs."""
from __future__ import print_function
@ -50,8 +49,8 @@ def guide_get_feature(route_guide_stub):
guide_get_one_feature(
route_guide_stub,
route_guide_pb2.Point(latitude=409146138, longitude=-746188906))
guide_get_one_feature(
route_guide_stub, route_guide_pb2.Point(latitude=0, longitude=0))
guide_get_one_feature(route_guide_stub,
route_guide_pb2.Point(latitude=0, longitude=0))
def guide_list_features(route_guide_stub):
@ -102,7 +101,8 @@ def generate_messages():
def guide_route_chat(route_guide_stub):
responses = route_guide_stub.RouteChat(generate_messages())
for response in responses:
print("Received message %s at %s" % (response.message, response.location))
print("Received message %s at %s" %
(response.message, response.location))
def run():

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A gRPC server servicing both Greeter and RouteGuide RPCs."""
from concurrent import futures
@ -50,17 +49,19 @@ def _get_distance(start, end):
delta_lon_rad = math.radians(lon_2 - lon_1)
a = (pow(math.sin(delta_lat_rad / 2), 2) +
(math.cos(lat_rad_1) * math.cos(lat_rad_2) *
pow(math.sin(delta_lon_rad / 2), 2)))
(math.cos(lat_rad_1) * math.cos(lat_rad_2) * pow(
math.sin(delta_lon_rad / 2), 2)))
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
R = 6371000; # metres
return R * c;
R = 6371000
# metres
return R * c
class _GreeterServicer(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, {}!'.format(request.name))
return helloworld_pb2.HelloReply(
message='Hello, {}!'.format(request.name))
class _RouteGuideServicer(route_guide_pb2_grpc.RouteGuideServicer):
@ -104,7 +105,8 @@ class _RouteGuideServicer(route_guide_pb2_grpc.RouteGuideServicer):
prev_point = point
elapsed_time = time.time() - start_time
return route_guide_pb2.RouteSummary(point_count=point_count,
return route_guide_pb2.RouteSummary(
point_count=point_count,
feature_count=feature_count,
distance=int(distance),
elapsed_time=int(elapsed_time))
@ -120,9 +122,10 @@ class _RouteGuideServicer(route_guide_pb2_grpc.RouteGuideServicer):
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreeterServicer_to_server(_GreeterServicer(), server)
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(
_RouteGuideServicer(), server)
helloworld_pb2_grpc.add_GreeterServicer_to_server(_GreeterServicer(),
server)
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(_RouteGuideServicer(),
server)
server.add_insecure_port('[::]:50051')
server.start()
try:

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Common resources used in the gRPC route guide example."""
import json

@ -11,26 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Generates protocol messages and gRPC stubs."""
from grpc_tools import protoc
protoc.main(
(
'',
'-I../../protos',
'--python_out=.',
'--grpc_python_out=.',
'../../protos/helloworld.proto',
)
)
protoc.main(
(
'',
'-I../../protos',
'--python_out=.',
'--grpc_python_out=.',
'../../protos/route_guide.proto',
)
)
protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.',
'../../protos/helloworld.proto',))
protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.',
'../../protos/route_guide.proto',))

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Python implementation of the gRPC route guide client."""
from __future__ import print_function
@ -44,7 +43,8 @@ def guide_get_one_feature(stub, point):
def guide_get_feature(stub):
guide_get_one_feature(stub, route_guide_pb2.Point(latitude=409146138, longitude=-746188906))
guide_get_one_feature(
stub, route_guide_pb2.Point(latitude=409146138, longitude=-746188906))
guide_get_one_feature(stub, route_guide_pb2.Point(latitude=0, longitude=0))
@ -94,7 +94,8 @@ def generate_messages():
def guide_route_chat(stub):
responses = stub.RouteChat(generate_messages())
for response in responses:
print("Received message %s at %s" % (response.message, response.location))
print("Received message %s at %s" %
(response.message, response.location))
def run():

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Common resources used in the gRPC route guide example."""
import json

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Python implementation of the gRPC route guide server."""
from concurrent import futures
@ -48,11 +47,13 @@ def get_distance(start, end):
delta_lon_rad = math.radians(lon_2 - lon_1)
a = (pow(math.sin(delta_lat_rad / 2), 2) +
(math.cos(lat_rad_1) * math.cos(lat_rad_2) *
pow(math.sin(delta_lon_rad / 2), 2)))
(math.cos(lat_rad_1) * math.cos(lat_rad_2) * pow(
math.sin(delta_lon_rad / 2), 2)))
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
R = 6371000; # metres
return R * c;
R = 6371000
# metres
return R * c
class RouteGuideServicer(route_guide_pb2_grpc.RouteGuideServicer):
"""Provides methods that implement functionality of route guide server."""
@ -95,7 +96,8 @@ class RouteGuideServicer(route_guide_pb2_grpc.RouteGuideServicer):
prev_point = point
elapsed_time = time.time() - start_time
return route_guide_pb2.RouteSummary(point_count=point_count,
return route_guide_pb2.RouteSummary(
point_count=point_count,
feature_count=feature_count,
distance=int(distance),
elapsed_time=int(elapsed_time))
@ -111,8 +113,8 @@ class RouteGuideServicer(route_guide_pb2_grpc.RouteGuideServicer):
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(
RouteGuideServicer(), server)
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(RouteGuideServicer(),
server)
server.add_insecure_port('[::]:50051')
server.start()
try:
@ -121,5 +123,6 @@ def serve():
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()

@ -11,17 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Runs protoc with the gRPC plugin to generate messages and gRPC stubs."""
from grpc_tools import protoc
protoc.main(
(
'',
'-I../../protos',
'--python_out=.',
'--grpc_python_out=.',
'../../protos/route_guide.proto',
)
)
protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.',
'../../protos/route_guide.proto',))

@ -738,7 +738,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
}
if (gpr_cv_wait(&worker->cv, &pollset->mu,
grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME)) &&
grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)) &&
worker->state == UNKICKED) {
/* If gpr_cv_wait returns true (i.e a timeout), pretend that the worker
received a kick */

@ -1471,7 +1471,7 @@ static void run_poll(void* args) {
decref_poll_result(result);
// Leave this polling thread alive for a grace period to do another poll()
// op
gpr_timespec deadline = gpr_now(GPR_CLOCK_REALTIME);
gpr_timespec deadline = gpr_now(GPR_CLOCK_MONOTONIC);
deadline = gpr_time_add(deadline, thread_grace);
pargs->trigger_set = 0;
gpr_cv_wait(&pargs->trigger, &g_cvfds.mu, deadline);
@ -1526,9 +1526,9 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) {
}
}
gpr_timespec deadline = gpr_now(GPR_CLOCK_REALTIME);
gpr_timespec deadline = gpr_now(GPR_CLOCK_MONOTONIC);
if (timeout < 0) {
deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
} else {
deadline =
gpr_time_add(deadline, gpr_time_from_millis(timeout, GPR_TIMESPAN));
@ -1631,7 +1631,7 @@ static void global_cv_fd_table_shutdown() {
// Not doing so will result in reported memory leaks
if (!gpr_unref(&g_cvfds.pollcount)) {
int res = gpr_cv_wait(&g_cvfds.shutdown_cv, &g_cvfds.mu,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_seconds(3, GPR_TIMESPAN)));
GPR_ASSERT(res == 0);
}

@ -155,7 +155,7 @@ static void executor_thread(void* arg) {
ts->depth -= subtract_depth;
while (grpc_closure_list_empty(ts->elems) && !ts->shutdown) {
ts->queued_long_job = false;
gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
if (ts->shutdown) {
if (executor_trace.enabled()) {

@ -118,7 +118,7 @@ void grpc_iomgr_shutdown() {
abort();
}
gpr_timespec short_deadline =
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_millis(100, GPR_TIMESPAN));
if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) {
if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) >

@ -192,7 +192,7 @@ static bool wait_until(grpc_millis next) {
}
gpr_cv_wait(&g_cv_wait, &g_mu,
grpc_millis_to_timespec(next, GPR_CLOCK_REALTIME));
grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC));
if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "wait ended: was_timed:%d kicked:%d",
@ -317,7 +317,7 @@ static void stop_threads(void) {
gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count);
}
while (g_thread_count > 0) {
gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count);
}

@ -66,7 +66,12 @@ int gpr_mu_trylock(gpr_mu* mu) {
/*----------------------------------------*/
void gpr_cv_init(gpr_cv* cv) {
GPR_ASSERT(pthread_cond_init(cv, nullptr) == 0);
pthread_condattr_t attr;
GPR_ASSERT(pthread_condattr_init(&attr) == 0);
#if GPR_LINUX
GPR_ASSERT(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0);
#endif // GPR_LINUX
GPR_ASSERT(pthread_cond_init(cv, &attr) == 0);
}
void gpr_cv_destroy(gpr_cv* cv) { GPR_ASSERT(pthread_cond_destroy(cv) == 0); }
@ -78,7 +83,11 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
err = pthread_cond_wait(cv, mu);
} else {
struct timespec abs_deadline_ts;
#if GPR_LINUX
abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_MONOTONIC);
#else
abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME);
#endif // GPR_LINUX
abs_deadline_ts.tv_sec = (time_t)abs_deadline.tv_sec;
abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec;
err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts);

@ -115,7 +115,7 @@ static grpc_error* non_polling_poller_work(grpc_pollset* pollset,
}
w.kicked = false;
gpr_timespec deadline_ts =
grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME);
grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC);
while (!npp->shutdown && !w.kicked &&
!gpr_cv_wait(&w.cv, &npp->mu, deadline_ts))
;

@ -1170,7 +1170,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server,
gpr_mu_lock(&server->mu_global);
while (server->starting) {
gpr_cv_wait(&server->starting_cv, &server->mu_global,
gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
/* stay locked, and gather up some stuff to do */

@ -115,7 +115,7 @@ static void cpu_test(void) {
}
gpr_mu_lock(&ct.mu);
while (!ct.is_done) {
gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(&ct.mu);
fprintf(stderr, "Saw cores [");

@ -73,7 +73,7 @@ void queue_append(queue* q, int x) {
corresponding condition variable. The predicate must be on state
protected by the lock. */
while (q->length == N) {
gpr_cv_wait(&q->non_full, &q->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_cv_wait(&q->non_full, &q->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
if (q->length == 0) { /* Wake threads blocked in queue_remove(). */
/* It's normal to use gpr_cv_broadcast() or gpr_signal() while
@ -197,7 +197,7 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) {
static void test_wait(struct test* m) {
gpr_mu_lock(&m->mu);
while (m->done != 0) {
gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(&m->mu);
}
@ -297,7 +297,7 @@ static void inc_by_turns(void* v /*=m*/) {
for (i = 0; i != m->iterations; i++) {
gpr_mu_lock(&m->mu);
while ((m->counter % m->threads) != id) {
gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
m->counter++;
gpr_cv_broadcast(&m->cv);
@ -314,7 +314,7 @@ static void inc_with_1ms_delay(void* v /*=m*/) {
for (i = 0; i != m->iterations; i++) {
gpr_timespec deadline;
gpr_mu_lock(&m->mu);
deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_micros(1000, GPR_TIMESPAN));
while (!gpr_cv_wait(&m->cv, &m->mu, deadline)) {
}
@ -370,14 +370,14 @@ static void consumer(void* v /*=m*/) {
int64_t i;
int value;
for (i = 0; i != n; i++) {
queue_remove(&m->q, &value, gpr_inf_future(GPR_CLOCK_REALTIME));
queue_remove(&m->q, &value, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_lock(&m->mu);
m->counter = n;
gpr_mu_unlock(&m->mu);
GPR_ASSERT(
!queue_remove(&m->q, &value,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_micros(1000000, GPR_TIMESPAN))));
mark_thread_done(m);
}

@ -126,7 +126,7 @@ void CliCall::WriteAndWait(const grpc::string& request) {
call_->Write(send_buffer, tag(2));
write_done_ = false;
while (!write_done_) {
gpr_cv_wait(&write_cv_, &write_mu_, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_cv_wait(&write_cv_, &write_mu_, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(&write_mu_);
}
@ -136,7 +136,7 @@ void CliCall::WritesDoneAndWait() {
call_->WritesDone(tag(4));
write_done_ = false;
while (!write_done_) {
gpr_cv_wait(&write_cv_, &write_mu_, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_cv_wait(&write_cv_, &write_mu_, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(&write_mu_);
}

@ -19,11 +19,13 @@ set -ex
cd "$(dirname "${0}")/../.."
DIRS=(
'examples/python'
'src/python'
'tools'
)
EXCLUSIONS=(
'*protoc_lib_deps.py' # this file is auto-generated
'*_pb2*.py' # no need to format protoc generated files
)
VIRTUALENV=yapf_virtual_environment

@ -0,0 +1,9 @@
set noparent
# These owners are in place to ensure that scenario_result_schema.json is not
# modified without also running tools/run_tests/performance/patch_scenario_results_schema.py
# to update the BigQuery schema
@ncteisen
@matt-kwong
@ctiller
Loading…
Cancel
Save