GithubHelp home page GithubHelp logo

gooddbird / tinyrpc Goto Github PK

View Code? Open in Web Editor NEW
1.2K 7.0 189.0 2.04 MB

c++ async rpc framework. 14w+qps.

License: Apache License 2.0

C++ 83.25% Assembly 0.34% Makefile 1.95% Python 8.94% Shell 3.36% CMake 1.59% Dockerfile 0.58%
coroutines protobuf reactor rpc

tinyrpc's People

Contributors

gooddbird avatar lovebettygirl avatar ning2510 avatar peidon 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  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

tinyrpc's Issues

testcases中test_rpc_server1.cc与test_rpc_server2.cc是否需要更新一下

这两个文件是否需要更新一下与quick_rpc_test.md保持一致😀
在test_rpc_server1.cc文件中会休眠6s

DebugLog << "this is query_name func";
DebugLog << "first begin to sleep 6s";
sleep_hook(6);
DebugLog << "sleep 6s end";

而在test_rpc_server2.cc中tcp_connection的超时时间为1s。

rpc_controller.SetTimeout(1000);

导致在使用测试用例时,会出现包发出去还没收到,此时就超时了,导致无法看到返回结果,会让人感到疑惑
[2022-05-18 12:19:25.94814] [INFO] [53269] [53269] [1] [tinyrpc/net/tcp/tcp_connection.cc:214] send[79] bytes data to [127.0.0.1:39999], fd [13]
[2022-05-18 12:19:25.94839] [INFO] [53269] [53269] [1] [tinyrpc/net/tcp/tcp_connection.cc:217] send all data, now unregister write event and break
[2022-05-18 12:19:25.94865] [DEBUG] [53269] [53269] [1] [tinyrpc/net/tcp/tcp_connection.cc:279] 82061641944973154118|reply data not exist
[2022-05-18 12:19:25.94889] [DEBUG] [53269] [53269] [1] [tinyrpc/net/tcp/tcp_connection.cc:114] m_read_buffer size=128rd=0wd=0
[2022-05-18 12:19:25.94914] [DEBUG] [53269] [53269] [1] [tinyrpc/coroutine/coroutine_hook.cc:55] this is hook read
[2022-05-18 12:19:25.94956] [DEBUG] [53269] [53269] [1] [tinyrpc/net/fd_event.cc:120] fd already set o_nonblock
[2022-05-18 12:19:25.94984] [DEBUG] [53269] [53269] [1] [tinyrpc/coroutine/coroutine_hook.cc:34] fd:[13], register read event to epoll
[2022-05-18 12:19:25.95009] [DEBUG] [53269] [53269] [1] [tinyrpc/net/reactor.cc:179] epoll_ctl add succ, fd[13]
[2022-05-18 12:19:25.95031] [DEBUG] [53269] [53269] [1] [tinyrpc/coroutine/coroutine_hook.cc:87] read func to yield
[2022-05-18 12:19:26.55967] [INFO] [53269] [53269] [0] [tinyrpc/net/tcp/tcp_client.cc:49] TcpClient timer out event occur

protobuf安装问题

”注意将头文件和库文件 copy 到对应的系统路径下。“
这是指的把哪些文件放在哪里啊?

TCP buffer处好像有一个bug

void TcpBuffer::recycleWrite(int index) {
  int j = m_write_index + index;
  //TODO: here get a bug
  if (j >= (int)m_buffer.size()) {
    ErrorLog << "recycleWrite error";
    return;
  }
  m_write_index = j;
  adjustBuffer();
}

此处是否有bug,当buffer被填满时,例如
[2022-05-18 03:04:04.214972] [DEBUG] [29062] [29064] [1] [tinyrpc/net/tcp/tcp_connection.cc:114] m_read_buffer size=128rd=0wd=0
[2022-05-18 03:04:04.214988] [DEBUG] [29062] [29064] [1] [tinyrpc/coroutine/coroutine_hook.cc:55] this is hook read
[2022-05-18 03:04:04.214998] [DEBUG] [29062] [29064] [1] [tinyrpc/net/fd_event.cc:121] fd already set o_nonblock
[2022-05-18 03:04:04.215017] [DEBUG] [29062] [29064] [1] [tinyrpc/net/tcp/tcp_connection.cc:116] read_hook func get size: 128
此时读到了128个byte,但是在调用recycleWrite时,由于0+128 >= 128而导致返回,引发后续错误

无任何改动,执行test_coroutine产生core_dump

(gdb) bt
#0 0x000055ef99818064 in tinyrpc::Coroutine::Coroutine (this=0x55ef9b3c1b80) at /usr/include/c++/9/bits/shared_ptr_base.h:1020
#1 0x000055ef99818bfd in tinyrpc::Coroutine::Coroutine(int, char*, std::function<void ()>) (this=0x55ef9b3c2180, size=, stack_ptr=, cb=...)
at tinyrpc/coroutine/coroutine.cc:87
#2 0x000055ef99816c05 in __gnu_cxx::new_allocatortinyrpc::Coroutine::construct<tinyrpc::Coroutine, int&, char*&, void (&)()> (__p=0x55ef9b3c2180, this=)
at /usr/include/c++/9/new:174
#3 std::allocator_traits<std::allocatortinyrpc::Coroutine >::construct<tinyrpc::Coroutine, int&, char*&, void (&)()> (__p=0x55ef9b3c2180, __a=...) at /usr/include/c++/9/bits/alloc_traits.h:483
#4 std::_Sp_counted_ptr_inplace<tinyrpc::Coroutine, std::allocatortinyrpc::Coroutine, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<int&, char*&, void (&)()> (__a=..., this=0x55ef9b3c2170)
at /usr/include/c++/9/bits/shared_ptr_base.h:548
#5 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<tinyrpc::Coroutine, std::allocatortinyrpc::Coroutine, int&, char*&, void (&)()> (__a=..., __p=,
this=) at /usr/include/c++/9/bits/shared_ptr_base.h:679
#6 std::__shared_ptr<tinyrpc::Coroutine, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocatortinyrpc::Coroutine, int&, char*&, void (&)()> (__tag=..., this=)
at /usr/include/c++/9/bits/shared_ptr_base.h:1344
#7 std::shared_ptrtinyrpc::Coroutine::shared_ptr<std::allocatortinyrpc::Coroutine, int&, char*&, void (&)()> (__tag=..., this=) at /usr/include/c++/9/bits/shared_ptr.h:359
#8 std::allocate_shared<tinyrpc::Coroutine, std::allocatortinyrpc::Coroutine, int&, char*&, void (&)()> (__a=...) at /usr/include/c++/9/bits/shared_ptr.h:702
#9 std::make_shared<tinyrpc::Coroutine, int&, char*&, void (&)()> () at /usr/include/c++/9/bits/shared_ptr.h:718
#10 main (argc=, argv=) at testcases/test_coroutine.cc:44

C++ 版本问题

/usr/local/include/absl/base/policy_checks.h:79:2: error: #error "C++ versions less than C++14 are not supported."
这个问题是因为什么呢?怎么解决呢?

编译时 protobuf 链接出错

第一次make时protobuf显式至少C++版本至少是C++14, 手动修改makefile的编译选项为-std=c++14之后有如下链接问题

/usr/bin/ld: extension_set.cc:(.text+0x906e): undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
/usr/bin/ld: /usr/local/lib/libprotobuf.a(extension_set.cc.o): in function `google::protobuf::internal::ExtensionSet::SetRepeatedEnum(int, int, int)':
extension_set.cc:(.text+0x910e): undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: extension_set.cc:(.text+0x9150): undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
/usr/bin/ld: extension_set.cc:(.text+0x91d7): undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: extension_set.cc:(.text+0x91ef): undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
/usr/bin/ld: extension_set.cc:(.text+0x9270): undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: extension_set.cc:(.text+0x9288): undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
/usr/bin/ld: extension_set.cc:(.text+0x92c6): undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()

protobuf版本
image

安装TinyRPC编译出错

CMake Error at /usr/local/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/local/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.27/Modules/FindProtobuf.cmake:652 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:28 (find_package)
用cmake方式编译时出错,这是为什么

error:no such file <tinyxml/tinyxml.h>

When I compile the project, the error message is
In file included from tinyrpc/comm/log.cc:16: tinyrpc/comm/config.h:4:10: fatal error: tinyxml/tinyxml.h: No such file or directory
How should I solve it?

定时器中的resetArriveTime(),不应该是以第一个TimerEvent的arrivedTime作为Timer的新的arrivedTime吗?(应该是auto it = tmp.begin(),而不是auto it = tmp.rbegin())

void Timer::resetArriveTime() {
  RWMutex::ReadLock lock(m_event_mutex);
  std::multimap<int64_t, TimerEvent::ptr> tmp = m_pending_events;
  lock.unlock();

  if (tmp.size() == 0) {
    DebugLog << "no timerevent pending, size = 0";
    return;
  }

  auto it = tmp.rbegin();
  int64_t interval = (*it).first - getNowMs();
  if (interval < 0) {
    DebugLog << "all timer events has already expire";
    return;
  }

  timespec ts;
  memset(&ts, 0, sizeof(ts));
  ts.tv_sec = interval / 1000;
  ts.tv_nsec = (interval % 1000) * 1000000;
  
  itimerspec new_value;
  memset(&new_value, 0, sizeof(new_value));
  new_value.it_value = ts;

  int rt = timerfd_settime(m_fd, 0, &new_value, nullptr);

  if (rt != 0) {
    ErrorLog << "tiemr_settime error, interval=" << interval;
  } else {
    DebugLog << "reset timer succ, next occur time=" << (*it).first;
  }
}

关于tinypb协议的疑问

您好,我看到业务接口是通过.proto文件定义的,我的理解是protobuf根据这个文件来做序列化反序列化。但是tinypb实际上也自己规定了一些字段,其中就包含了.proto消息序列化后的字符串,而tinypb在代码里是手动序列化反序列化的。我的问题是,为什么不直接全部用protobuf来处理rpc通信的消息,而要在外层封装一层tinypb还要手动序列化呢?

(刚接触rpc,之前没有实际业务经验,目前正在通过您的项目学习这一块的内容。)

在初始化MySQL实例的时候coredump

想问下作者,在调用QueryServiceImpl::query_name这个服务的时候,当执行到instase初始化那一行代码的时候服务器就崩溃了。我本地自己起了一个mysql数据库,然后配置文件中的mysql相应配置部分内容也改了,并且我自己写了一个小demo来测试mysql的连接状况,也没出什么问题。所以想问问作者,这可能是什么原因导致的呢,疑惑好几天了....

testcast执行失败

安装完成后想运行一下testcast的例子,运行失败了。运行的命令如下

g++ test_tinypb_server.cc ../lib/libtinyrpc.a -o test_tinypb_server 

报的错误是找不相关引用,比如:

/usr/bin/ld: /tmp/ccBramt5.o:(.data.rel.ro._ZTV16QueryServiceImpl[_ZTV16QueryServiceImpl]+0x30): undefined reference to `QueryService::GetRequestPrototype(google::protobuf::MethodDescriptor const*) const'

/root/tinyrpc-main/tinyrpc/comm/config.cc:31: undefined reference to `TiXmlElement::GetText() const'
/usr/bin/ld: /root/tinyrpc-main/tinyrpc/comm/config.cc:35: undefined reference to `TiXmlElement::GetText() const'

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.