Giter VIP home page Giter VIP logo

grpc's Introduction

grpc

An R library for GRPC a high-performance, open-source universal RPC framework.

Installation - Debian

Pre-requisites

The following is copied from gRPC C++ - Building from source

sudo apt-get install build-essential autoconf libtool pkg-config
## If you plan to build from source and run tests, install the following as well:
sudo apt-get install libgflags-dev libgtest-dev
sudo apt-get install clang libc++-dev

Download and Install grpc

export GRPC_INSTALL_DIR=$HOME/.local
mkdir -p $GRPC_INSTALL_DIR
export PATH="$GRPC_INSTALL_DIR/bin:$PATH"

sudo apt install -y cmake

LATEST_VER=$(curl -L "https://api.github.com/repos/grpc/grpc/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')
git clone --recurse-submodules -b $LATEST_VER https://github.com/grpc/grpc grpc_base

cd grpc_base
mkdir -p cmake/build
pushd cmake/build
cmake -DgRPC_INSTALL=ON \
      -DgRPC_BUILD_TESTS=OFF \
      -DCMAKE_INSTALL_PREFIX=$GRPC_INSTALL_DIR \
      ../..
make -j4
sudo make install
popd

mkdir -p third_party/abseil-cpp/cmake/build
pushd third_party/abseil-cpp/cmake/build
cmake -DCMAKE_INSTALL_PREFIX=$GRPC_INSTALL_DIR \
      -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
      ../..
make -j4
sudo make install
popd

Original

Build Status

Easily create gRPC clients and servers from protobuf descriptions to build distributed services.

Copyright 2015 Google Inc, 2017 Neal Fultz

Dependencies

  • grpc
  • protobuf
  • RProtoBuf

See install for my installation notes...

Examples

There are runnable examples in the demo/ folder.

Hello, World!

To start a HelloWorld server:

R -e 'demo("helloserver", "grpc")'

Or with much more detailed logging:

R -e 'library(futile.logger); flog.threshold(TRACE); demo("helloserver", "grpc")'

To run a client against a running HelloWorld server:

R -e 'demo("helloclient", "grpc")'

Both are cross compatible with the Node, Python and C++ Greeter examples provided by the grpc library.

Health check

This server implements the above service along with the standard GRPC Health Checking Protocol:

R -e 'demo("health-check-server", "grpc")'

The client runs a health-check then calls the Hello, World! method once:

R -e 'demo("health-check-client", "grpc")'

Please check the sources of the server to see how to bundle services defined in multiple proto files.

Live scoring

There's a simple trained on the iris dataset and making that available for scoring via a gRPC service:

R -e 'demo("iris-server", "grpc")'

An example client to this service from R:

R -e 'demo("iris-client", "grpc")'

Todo

  • Streaming services
  • Authentication and Encryption
  • Error handling
  • Docs

Contributing

grpc's People

Contributors

daroczig avatar florianschwendinger avatar nfultz avatar shehab7osny avatar sieverssj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grpc's Issues

Installing on windows

Is it possible to get the package installed on MS Windows . I did run into the following error:

> devtools::install_github("nfultz/grpc")
Downloading GitHub repo nfultz/grpc@master
from URL https://api.github.com/repos/nfultz/grpc/zipball/master
Installing grpc
"C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  "C:/Users/wolski/AppData/Local/Temp/RtmpuwKZn5/devtools20904dbd502/nfultz-grpc-0b08d64" --library="C:/Users/wolski/Documents/R/win-library/3.5"  \
  --install-tests 

* installing *source* package 'grpc' ...
** libs
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/include" -DNDEBUG  -I"C:/Users/wolski/Documents/R/win-library/3.5/Rcpp/include"   -I"C:/swarm/workspace/External-R-3.5.1/vendor/extsoft/include"  `pkg-config --cflags grpc`   -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
pkg-config: not found
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/include" -DNDEBUG  -I"C:/Users/wolski/Documents/R/win-library/3.5/Rcpp/include"   -I"C:/swarm/workspace/External-R-3.5.1/vendor/extsoft/include"  `pkg-config --cflags grpc`   -O2 -Wall  -mtune=core2 -c client.cpp -o client.o
pkg-config: not found
client.cpp:2:23: fatal error: grpc/grpc.h: No such file or directory
 #include <grpc/grpc.h>
                       ^
compilation terminated.
make: *** [client.o] Error 1
ERROR: compilation failed for package 'grpc'
* removing 'C:/Users/wolski/Documents/R/win-library/3.5/grpc'
In R CMD INSTALL
Installation failed: Command failed (1)

Can read_services use readProtoFiles2 which has an equivalent of proto_path for imports?

I have a proto file that has a few imports on proto files in other packages and readProtoFiles simply blows up with errors because it doesn't know where to find the imports.
readProtoFiles2 was introduced to fix that issue eddelbuettel/rprotobuf#39 and https://www.rdocumentation.org/packages/RProtoBuf/versions/0.4.14/topics/readProtoFiles. So can read_services use readProtoFiles2 and allow us to specify proto_path?

Grpc Server crash

Hello, I'm trying to include this library in a suit of grpc benchmarks.

I have an issue with the server, when I send requests from a ghz client it fails with this error:

E0805 16:39:28.639090500       1 byte_buffer.cc:91]          Should never reach here.

 *** caught segfault ***
address (nil), cause 'unknown'

Traceback:
 1: run(server_functions, channel, hooks)
 2: start_server(impl, "0.0.0.0:50051")
An irrecoverable exception occurred. R is aborting now ...

It's possible to reproduce this on a linux or macos machine by just cloning this branch: https://github.com/LesnyRumcajs/grpc_bench/tree/r-bench

(the relevant code is inside the r_grpc directory)

Build the docker image with the server
docker build --force-rm -f r_grpc/Dockerfile -t r_grpc_test .

Start the server
docker run --rm -it --network host r_grpc_test

Start the client
docker run --rm --network=host -v "${PWD}"/proto:/proto:ro --entrypoint=ghz infoblox/ghz:0.0.1 --proto=/proto/helloworld/helloworld.proto --call=helloworld.Greeter.SayHello --insecure --connections=5 --duration 5s -d "{\"name\":\"it's not as performant as we expected\"}" 127.0.0.1:50051

output of the client:

Status code distribution:
  [OK]            4 responses        
  [Unavailable]   273676 responses   
  [Canceled]      41 responses 

I may be doing some silly mistake in the server implementation.

Support multiple clients at once.

Right now, server mode can only handle one client at a time - the first client must hang up before the server can begin processing the second request.

To fix this, for each request, we should run each response in a different thread drawn from a thread pool.

Initially I planned on using RcppParallel, but it's README explicitly says not to access any R APIs from its workers.

My alternative plan is modify the server callback wrapper code to call through mcparallel - this will preclude (theoretical anyway) windows support, but is the next step towards fully implementing the grpc api.

Possible bug in helloserver/client

Filling this possible issue mostly just for possible confirmation that it is not just me who is experiencing the issue

message of type 'helloworld.GreetingReply' with one field set

$message

[1] "Hello, Neal"

Error in client$SayThanks$callWithMetadata(thanks, c("key1", "val1")) :

attempt to apply non-function

Any other possibly relevant information would be much appreciated.

Cheers!

too many open files

@nfultz, did you see any issues with letting the service run for a longer time?

Everything seems to work perfectly fine while running a grpc service in Docker for a while, and the service responds to requests, but after ~25 mins the process fails with:

{"log":"E0106 00:37:51.980090342       1 tcp_server_posix.c:245]     Failed accept4: Too many open files\n","stream":"stderr","time":"2018-01-06T00:37:51.98024391Z"}

Any chance that the server does not free up some resources in the loops or any other ideas?

loglevel

Can you pls add an argument/option to suppress the detailed logs from the C calls? Eg a verbose option would be great. I think in most cases the users will be only interested at the app-level logs written from R, the verbose option will be rather useful for the gRpc pkg devs.

Compilation error

I am using Ubuntu 16.04, and R 3.4.4.

I tried to follow the installation instruction (https://github.com/nfultz/grpc/blob/master/install) with no problem.

I also try to install the R package following (#18)

R CMD build grpc/
R -e "install.packages(dir(pattern = 'grpc.*.tar.gz'), repos=NULL)"

However, during compilation, I get the following error. Do you know how I may solve the problem?

> install.packages(dir(pattern = 'grpc.*.tar.gz'), repos=NULL)
Installing package into ‘/home/don/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
* installing *source* package ‘grpc’ ...
** libs
g++  -I/usr/share/R/include -DNDEBUG  -I"/home/don/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include"   `pkg-config --cflags grpc` -fpic  -g 
-O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
g++  -I/usr/share/R/include -DNDEBUG  -I"/home/don/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include"   `pkg-config --cflags grpc` -fpic  -g 
-O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c client.cpp -o client.o
client.cpp:13:23: error: ‘grpc_slice’ was not declared in this scope
 RawVector sliceToRaw2(grpc_slice slice){
                       ^
client.cpp:13:40: error: expected ‘,’ or ‘;’ before ‘{’ token
 RawVector sliceToRaw2(grpc_slice slice){
                                        ^
client.cpp: In function ‘Rcpp::RawVector fetch(Rcpp::CharacterVector, Rcpp::CharacterVector, Rcpp::RawVector)’:

                                        ^                                                                                          
client.cpp: In function ‘Rcpp::RawVector fetch(Rcpp::CharacterVector, Rcpp::CharacterVector, Rcpp::RawVector)’:
client.cpp:42:73: error: ‘grpc_completion_queue_create_for_next’ was not declared in this scope
   grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
                                                                         ^
client.cpp:44:9: error: ‘grpc_slice’ does not name a type
   const grpc_slice server_slice = grpc_slice_from_copied_string(server[0]);
         ^
client.cpp:45:9: error: ‘grpc_slice’ does not name a type
   const grpc_slice method_slice = grpc_slice_from_copied_string(method[0]);
         ^
client.cpp:49:3: error: ‘grpc_slice’ was not declared in this scope
   grpc_slice request_payload_slice = grpc_slice_from_copied_buffer((char*) RAW(raw_), len);
   ^
client.cpp:52:9: error: ‘grpc_slice’ does not name a type
   const grpc_slice *sp = &server_slice;
         ^
client.cpp:61:5: error: ‘method_slice’ was not declared in this scope
     method_slice, //grpc_slice_from_static_string("/foo"),
     ^
client.cpp:62:5: error: ‘sp’ was not declared in this scope
     sp, 
     ^
client.cpp:79:14: error: expected ‘;’ before ‘details’
   grpc_slice details;
              ^
client.cpp:91:34: error: ‘request_payload_slice’ was not declared in this scope
     grpc_raw_byte_buffer_create(&request_payload_slice, 1);
                                  ^
client.cpp:97:34: error: ‘struct grpc_op::<anonymous union>::<anonymous>’ has no member named ‘maybe_compression_level’
   op->data.send_initial_metadata.maybe_compression_level.is_set = false;
                                  ^
client.cpp:102:25: error: request for member ‘send_message’ in ‘op->grpc_op::data.grpc_op::<anonymous union>::send_message’, which is of poi
nter type ‘grpc_byte_buffer*’ (maybe you meant to use ‘->’ ?)
client.cpp:102:25: error: request for member ‘send_message’ in ‘op->grpc_op::data.grpc_op::<anonymous union>::send_message’, which is of pointer type ‘grpc_byte_buffer*’ (maybe you meant to use ‘->’ ?)
   op->data.send_message.send_message = request_payload;
                         ^
client.cpp:111:34: error: request for member ‘recv_initial_metadata’ in ‘op->grpc_op::data.grpc_op::<anonymous union>::recv_initial_metadata
’, which is of pointer type ‘grpc_metadata_array*’ (maybe you meant to use ‘->’ ?)
   op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv;
                                  ^
client.cpp:116:25: error: request for member ‘recv_message’ in ‘op->grpc_op::data.grpc_op::<anonymous union>::recv_message’, which is of non
-class type ‘grpc_byte_buffer**’
   op->data.recv_message.recv_message = &response_payload_recv;
                         ^
client.cpp:123:52: error: ‘details’ was not declared in this scope
   op->data.recv_status_on_client.status_details = &details;
                                                    ^
client.cpp:150:14: error: expected ‘;’ before ‘response_payload_slice’
   grpc_slice response_payload_slice = grpc_byte_buffer_reader_readall(&bbr);
              ^
client.cpp:151:48: error: ‘response_payload_slice’ was not declared in this scope
   RawVector response_payload_raw = sliceToRaw2(response_payload_slice);
                                                ^
client.cpp:165:27: error: ‘grpc_slice_unref’ was not declared in this scope
   grpc_slice_unref(details);
                           ^
/usr/lib/R/etc/Makeconf:168: recipe for target 'client.o' failed
make: *** [client.o] Error 1
ERROR: compilation failed for package ‘grpc’
* removing ‘/home/don/R/x86_64-pc-linux-gnu-library/3.4/grpc’
Warning message:
In install.packages(dir(pattern = "grpc.*.tar.gz"), repos = NULL) :
  installation of package ‘grpc_0.1.0.tar.gz’ had non-zero exit status
> 

Thank you!
Don

Support configurable client deadlines in call()

Currently, RPC calls have a client-side deadline of 5 seconds, hard-coded in fetch() src/client.cc. We have some RPCs that take longer than that, that we'd like to call from R, so can this be made configurable from R?

Unable to install following install commands

I am trying to install this package for use on mac osx (so I'm skipping over the sudo ldconfig commands because I believe that is only for linux), however I seem to get an error when I get to the ./autogen.sh command with installing gmock.
It looks like these links have been updated in a more recent version of grpc here in this issue: grpc/grpc#7952
with this pull request/commit: protocolbuffers/protobuf@bba446b

I was able to successfully install grpc and run the ./autogen.sh command using a the most recent release branch following instructions here https://github.com/grpc/grpc/blob/master/INSTALL.md however, if I continue with the commands in the install file for this package I get an error at this point R CMD INSTALL grpc.
Warning: invalid package ‘grpc’ Error: ERROR: no packages specified
Is the R grpc package only installable via a particular grpc branch or am I missing something simple here?

Unable to build Docker image

I'm trying to build a docker image from inst/docker_stable/Dockerfile but the build crashes with the following error:

E: Unable to locate package libgrpc3

After updating the package version from libgrpc3 to libgrpc6 the build is still failing with an error:

Error: package or namespace load failed for ‘docopt’:
 package ‘stringi’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version
The command '/bin/sh -c install2.r -r https://cran.rstudio.com/ processx remotes' returned a non-zero code: 1

timeout or updater function

Hey @nfultz,

I'm thinking about a way to schedule some updates within the server function, so that eg I can keep up-to-date the cached data loaded at startup time. Image eg I load the iris dataset and build a model on server startup and using the model for scoring in a method, but I'd like to retrain the model from time to time.

Currently, I can achieve that by running the app behind a load balancer and killing one of the apps from time to time. Another way would be to add an Updater method and calling that from a scheduler -- but none of these are optimal.

In the AWR.Kinesis package, I do this by providing updater functions, which takes a list of frequencies and functions to run, and the server evaluates the functions at the provided frequencies: https://github.com/daroczig/AWR.Kinesis#writing-a-record-processor-application

I'd love to see such functionality in grpc as well :) Eg if we could run an R function inside of start_server every 60 mins or so.

But another, a probably much simpler solution would be to provide a timeout argument to start_server, which would automatically shut down after the provided number of minutes or similar -- that would resolve the auto-update feature behind an app load balancer pretty easily.

What do you think?

Cannot get the demo working

I've set up a Docker container running Ubuntu 21. I've followed the instructions under installation to make sure the necessary package dependencies are installed and that grpc is available. I then clone the repository, CD into the base directory and run R -e 'demo("helloserver", "grpc")'. I see:

root@dbf97d90098c:/tmp/grpc# R -e 'demo("helloserver", "grpc")'

R version 4.1.1 (2021-08-10) -- "Kick Things"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> demo("helloserver", "grpc")
Error in find.package(package, lib.loc, verbose = verbose) : 
  there is no package called 'grpc'
Calls: demo -> find.package
Execution halted

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.