Skip to content

Commit

Permalink
update tutorial format
Browse files Browse the repository at this point in the history
  • Loading branch information
holmes1412 committed Jul 30, 2020
1 parent e151e8d commit 71c9fd8
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 447 deletions.
2 changes: 1 addition & 1 deletion docs/about-connection-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ int some_function()
}
~~~
在这个示例中,当http task是连接上的首个请求是,我们设置了cookie。如果不是首个请求,根据约定,不再设置cookie。
另外,prepare函数里,可以安全的使用连接上下文。同一个连接上,prepare不会并发。
另外,prepare函数里,可以安全的使用连接上下文。同一个连接上,prepare不会并发。
2 changes: 1 addition & 1 deletion docs/about-counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@ public:
...
};
~~~
有需要的用户可以自行查阅相关代码。由于WFTaskFactory没有提供工厂函数,创造container任务需要自己调用new。
有需要的用户可以自行查阅相关代码。由于WFTaskFactory没有提供工厂函数,创造container任务需要自己调用new。
16 changes: 8 additions & 8 deletions docs/about-error.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ void callback(WFXxxTask *task)
~~~cpp
enum
{
WFT_STATE_UNDEFINED = -1,
WFT_STATE_SUCCESS = CS_STATE_SUCCESS,
WFT_STATE_TOREPLY = CS_STATE_TOREPLY, /* for server task only */
WFT_STATE_NOREPLY = CS_STATE_TOREPLY + 1, /* for server task only */
WFT_STATE_SYS_ERROR = CS_STATE_ERROR,
WFT_STATE_SSL_ERROR = 65,
WFT_STATE_DNS_ERROR = 66, /* for client task only */
WFT_STATE_TASK_ERROR = 67
WFT_STATE_UNDEFINED = -1,
WFT_STATE_SUCCESS = CS_STATE_SUCCESS,
WFT_STATE_TOREPLY = CS_STATE_TOREPLY, /* for server task only */
WFT_STATE_NOREPLY = CS_STATE_TOREPLY + 1, /* for server task only */
WFT_STATE_SYS_ERROR = CS_STATE_ERROR,
WFT_STATE_SSL_ERROR = 65,
WFT_STATE_DNS_ERROR = 66, /* for client task only */
WFT_STATE_TASK_ERROR = 67
};
~~~
##### 需要关注的几个状态:
Expand Down
38 changes: 18 additions & 20 deletions docs/about-service-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ using upstream_route_t = std::function<unsigned int (const char *, const char *,
class UpstreamManager
{
public:
static int upstream_create_consistent_hash(const std::string& name,
upstream_route_t consitent_hash);
static int upstream_create_consistent_hash(const std::string& name,
upstream_route_t consitent_hash);

static int upstream_create_weighted_random(const std::string& name,
bool try_another);

static int upstream_create_manual(const std::string& name,
upstream_route_t select,
bool try_another,
upstream_route_t consitent_hash);
static int upstream_create_weighted_random(const std::string& name,
bool try_another);

static int upstream_create_manual(const std::string& name,
upstream_route_t select,
bool try_another,
upstream_route_t consitent_hash);

static int upstream_delete(const std::string& name);
static int upstream_delete(const std::string& name);
...
};
~~~
Expand Down Expand Up @@ -137,7 +136,6 @@ int main()
UpstreamManager::upstream_add_server("redis.name", "10.135.35.55");
...
UpstreamManager::upstream_add_server("redis.name", "10.135.35.62");


auto *task = WFTaskFactory::create_redis_task("redis://:[email protected]/2?a=hello#111", ...);
...
Expand All @@ -164,21 +162,21 @@ struct EndpointParams
// In UpstreamMananger.h
struct AddressParams
{
struct EndpointParams endpoint_params; ///< Connection config
unsigned int dns_ttl_default; ///< in seconds, DNS TTL when network request success
unsigned int dns_ttl_min; ///< in seconds, DNS TTL when network request fail
struct EndpointParams endpoint_params; ///< Connection config
unsigned int dns_ttl_default; ///< in seconds, DNS TTL when network request success
unsigned int dns_ttl_min; ///< in seconds, DNS TTL when network request fail
/**
* - The max_fails directive sets the number of consecutive unsuccessful attempts to communicate with the server.
* - After 30s following the server failure, upstream probe the server with some live client’s requests.
* - If the probes have been successful, the server is marked as a live one.
* - If max_fails is set to 1, it means server would out of upstream selection in 30 seconds when failed only once
*/
unsigned int max_fails; ///< [1, INT32_MAX] max_fails = 0 means max_fails = 1
unsigned short weight; ///< [1, 65535] weight = 0 means weight = 1. only for master
#define SERVER_TYPE_MASTER 0
#define SERVER_TYPE_SLAVE 1
int server_type; ///< default is SERVER_TYPE_MASTER
int group_id; ///< -1 means no group. Slave without group will backup for any master
unsigned int max_fails; ///< [1, INT32_MAX] max_fails = 0 means max_fails = 1
unsigned short weight; ///< [1, 65535] weight = 0 means weight = 1. only for master
#define SERVER_TYPE_MASTER 0
#define SERVER_TYPE_SLAVE 1
int server_type; ///< default is SERVER_TYPE_MASTER
int group_id; ///< -1 means no group. Slave without group will backup for any master
};
~~~
大多数参数的作用一眼了然。其中endpoint_params和dns相关参数,可以覆盖全局的配置。
Expand Down
52 changes: 26 additions & 26 deletions docs/about-timeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
~~~cpp
struct EndpointParams
{
size_t max_connections;
int connect_timeout;
int response_timeout;
int ssl_connect_timeout;
size_t max_connections;
int connect_timeout;
int response_timeout;
int ssl_connect_timeout;
};

static constexpr struct EndpointParams ENDPOINT_PARAMS_DEFAULT =
{
.max_connections = 200,
.connect_timeout = 10 * 1000,
.response_timeout = 10 * 1000,
.ssl_connect_timeout = 10 * 1000,
.max_connections = 200,
.connect_timeout = 10 * 1000,
.response_timeout = 10 * 1000,
.ssl_connect_timeout = 10 * 1000,
};
~~~
其中,与超时相关的配置包括以下3项。
Expand All @@ -40,24 +40,24 @@ static constexpr struct EndpointParams ENDPOINT_PARAMS_DEFAULT =
~~~cpp
struct WFGlobalSettings
{
EndpointParams endpoint_params;
unsigned int dns_ttl_default;
unsigned int dns_ttl_min;
int dns_threads;
int poller_threads;
int handler_threads;
int compute_threads;
EndpointParams endpoint_params;
unsigned int dns_ttl_default;
unsigned int dns_ttl_min;
int dns_threads;
int poller_threads;
int handler_threads;
int compute_threads;
};

static constexpr struct WFGlobalSettings GLOBAL_SETTINGS_DEFAULT =
{
.endpoint_params = ENDPOINT_PARAMS_DEFAULT,
.dns_ttl_default = 12 * 3600, /* in seconds */
.dns_ttl_min = 180, /* reacquire when communication error */
.dns_threads = 8,
.poller_threads = 2,
.handler_threads = 20,
.compute_threads = -1
.endpoint_params = ENDPOINT_PARAMS_DEFAULT,
.dns_ttl_default = 12 * 3600, /* in seconds */
.dns_ttl_min = 180, /* reacquire when communication error */
.dns_threads = 8,
.poller_threads = 2,
.handler_threads = 20,
.compute_threads = -1
};
//compute_threads<=0 means auto-set by system cpu number
~~~
Expand Down Expand Up @@ -97,10 +97,10 @@ class WFNetworkTask : public CommRequest
{
...
public:
/* All in milleseconds. timeout == -1 for unlimited. */
void set_send_timeout(int timeout) { this->send_timeo = timeout; }
void set_receive_timeout(int timeout) { this->receive_timeo = timeout; }
void set_keep_alive(int timeout) { this->keep_alive_timeo = timeout; }
/* All in milleseconds. timeout == -1 for unlimited. */
void set_send_timeout(int timeout) { this->send_timeo = timeout; }
void set_receive_timeout(int timeout) { this->receive_timeo = timeout; }
void set_keep_alive(int timeout) { this->keep_alive_timeo = timeout; }
...
}
~~~
Expand Down
1 change: 0 additions & 1 deletion docs/about-timer.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# 关于定时器

和网络任务,计算任务或文件任务一样,定时器是我们框架中的一种基础任务。
定时器的作用是不占线程的等待一个确定时间,同样通过callback来通知定时器到期。

# 定时器的创建
Expand Down
Loading

0 comments on commit 71c9fd8

Please sign in to comment.