multilate源代码解读1 Connection

Posted 银灯玉箫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了multilate源代码解读1 Connection相关的知识,希望对你有一定的参考价值。

Connection: represents a new connection to a server endpoint

Connection.h
Connection has two event_bases. One is used to store the dns events. Another is used to represent the read/write events.

A bufferevent with 2 event_bases;

Constructor Function

Connection.cc

initialize the callback functions for read or write events

Connection maintains a enum status called write_state.

write_state is initialized with write_state.
When write_state changes its state to ISSUING. It invokes the function called issue_something(now) to genuinely send the current request.

Connection.cc

Issue either a get or set request to the server according to our probability distribution. For example, if we need to send a set request, we first generate the key str of this set request, and then the value str. Afterwards, we invoke the
issue_set function.

Issue a set request to the server.


Indeed, it delegates the protocol to send the request in fact at line 187. At line 184, it first push the operation into the stack.

std::queue<Operation> op_queue;

At line 186, it changes the read_state to "waiting for set ", meaning that the connection waits for the response of the set operation. In the meantime, we need to increment the amount of bytes that have been sent at line 188.

Protocol.cc
Finally, the set_reqquest function in Protocol.cc appends the key and value according to the memcached format to the end of the output buffer of the bufferevent. The data would be written to the descriptor automatically as it becomes available for writing.

以上是关于multilate源代码解读1 Connection的主要内容,如果未能解决你的问题,请参考以下文章

multilate源代码解读3 AgentStats.h ConnectionStats.h LogHistorgramSampler.h 三者联合起来统计latency

mysqlHikariCP不断打印WARN日志Failed to validate connection JDBC4Connectio Possibly consider using a shor

Data source rejected establishment of connection, message from server: &quot;Too many connectio

GLib-GIO-CRITICAL **: g_dbus_connection_register_object: assertion ‘G_IS_DBUS_CONNECTION (connectio

GLib-GIO-CRITICAL **: g_dbus_connection_register_object: assertion ‘G_IS_DBUS_CONNECTION (connectio

GLib-GIO-CRITICAL **: g_dbus_connection_register_object: assertion ‘G_IS_DBUS_CONNECTION (connectio