GithubHelp home page GithubHelp logo

Comments (8)

jinq0123 avatar jinq0123 commented on July 1, 2024

What do you mean?

from grpc-lua.

gonsalez-ru avatar gonsalez-ru commented on July 1, 2024

Service in your "Greeter" example will work until i kill this process with operating system command. I want to find the way to service shutdown by himself according to remote client command.

from grpc-lua.

jinq0123 avatar jinq0123 commented on July 1, 2024
function M.SayHello(request, replier)
    os.exit()
end -- SayHello()

Then the service will shutdown itself if the client requests rpc "SayHello".

from grpc-lua.

gonsalez-ru avatar gonsalez-ru commented on July 1, 2024

Yes, os.exit() works, but I exected another solution. :-(
I need the service gracefully finishes all started negotiations and passes control back to the main() routine next to the "svr:run()".

from grpc-lua.

jinq0123 avatar jinq0123 commented on July 1, 2024

Sorry, no such function. Maybe you can try to export shutdown() from C++ to lua.

from grpc-lua.

gonsalez-ru avatar gonsalez-ru commented on July 1, 2024

I've bind Shutdown function from <grpc_cb_core/server/server.h>. When I call it the service stop serving but dont return control. According to function desctiption there is an optional parameter Deadline wich can help us. Lua and C aren't my native languages, so I need your help in binding with parameters.

grpc-lua\src\cpp\server\BindServer.cpp
...
void BindServer(const LuaRef& mod)
{
using namespace grpc_cb_core;
LuaBinding(mod).beginClass("Server")
.addConstructor(LUA_ARGS())
// Returns bound port number on success, 0 on failure.
.addFunction("add_listening_port",
static_cast<int(Server::*)(const std::string&)>(
&Server::AddListeningPort))
.addFunction("register_service", &RegisterService)
.addFunction("run", &Server::Run)
.addFunction("shutdown", &Server::Shutdown)
.endClass(); // Server
} // BindServer()
...

grpc_lua\server\Server.lua
...
function Server:shutdown()
self.c_svr:shutdown()
end
...

grpc_cb_core\include\grpc_cb_core\server\server.h
...
/// Shutdown the server, blocking until all rpc processing finishes.
/// Forcefully terminate pending calls after \a deadline expires.
///
/// \param deadline How long to wait until pending rpcs are forcefully
/// terminated.
template
void Shutdown(const T& deadline) {
ShutdownInternal(TimePoint(deadline).raw_time());
}

/// Shutdown the server, waiting for all rpc processing to finish.
void Shutdown() { ShutdownInternal(gpr_inf_future(GPR_CLOCK_MONOTONIC)); }

/// Block waiting for all work to complete.
///
/// \warning The server must be either shutting down or some other thread must
/// call \a Shutdown for this function to ever return.
void Run();
...

How can I describe Shutdown(deadline) like this:
.addFunction("add_listening_port",
static_cast<int(Server::*)(const std::string&)>(
&Server::AddListeningPort))
?

Thank you in advance!

from grpc-lua.

jinq0123 avatar jinq0123 commented on July 1, 2024

I hope this can compile:

#include <chrono>
...

namespace {
...
void ShutdownDeadline(grpc_cb_core::Server* pServer, const LuaRef& timeoutSec)
{
    assert(pServer);
    std::chrono::system_clock::time_point t = std::chrono::system_clock::now();
    double dSec = timeoutSec.toValue<double>();
    t += std::chrono::seconds(dSec);
    pServer->Shutdown(t);
}

}  // namespace

namespace server {

void BindServer(const LuaRef& mod)
{
    ...
        .addFunction("shutdown_deadline", &ShutdownDeadline)
    ...
}  // BindServer()

}  // namespace server

from grpc-lua.

gonsalez-ru avatar gonsalez-ru commented on July 1, 2024

FAIL :-(

Shutdown with deadline gives the same result. Service stops without termination and loads processor up to 30%.

I'm stumped, so I just live compilable version here ...

grpc-lua\src\cpp\server\BindServer.cpp

#include <grpc/support/time.h>  // for gpr_timespec
#include <grpc/impl/codegen/gpr_types.h> //for gpr_clock_type
...
namespace {
...
void ShutdownDeadline(grpc_cb_core::Server* pServer, const LuaRef& timeoutSec)
{
    assert(pServer);
    int32_t mSec = timeoutSec.toValue<int32_t>()*1000;
    gpr_timespec t = gpr_time_from_millis(gpr_time_to_millis(gpr_now(GPR_CLOCK_MONOTONIC))+mSec,GPR_CLOCK_MONOTONIC);
    pServer->Shutdown(t);
}  //ShutdownDeadline()
}  // namespace

namespace server {

void BindServer(const LuaRef& mod)
{
...
        .addFunction("shutdown_deadline", &ShutdownDeadline)
...
}  // BindServer()

}  // namespace server

from grpc-lua.

Related Issues (14)

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.