Skip to content

Commit

Permalink
feat en readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ffengc committed Jul 7, 2024
1 parent d6a5c22 commit 4f311de
Show file tree
Hide file tree
Showing 7 changed files with 1,109 additions and 276 deletions.
577 changes: 301 additions & 276 deletions README.md

Large diffs are not rendered by default.

Binary file added assets/1-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
753 changes: 753 additions & 0 deletions docs/README-cn.md

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions docs/exp-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Experiments with different lambda combinations

- [简体中文](./exp.md)
- [English](./exp-en.md)

In the negative exponential distribution, if the parameter is larger, the number generated by the C++11 generator is smaller, which means that the smaller the time of `sleep()`, the more frequent the event. Secondly, the logic I set is that the server will exit only after the client closes the write end descriptor. Therefore, if the client has sent all the information, it will close the file descriptor of the intermediate pipeline. At this time, regardless of whether the server has read all the data, the server will exit directly. Thirdly, the logic I set is that each worker end of the client will exit by itself after sending 10 messages (a total of 30 messages) (this number can be changed in the configuration file).

**For easy observation, on the server side, I printed the cache size of the pc object for observation and analysis. **

**When the production rate is greater than the consumption rate:**

As shown in the figure, when the production rate is greater than the consumption rate, the cache maintained in the pc object on the server side is always at a high level, which is in line with expectations, because the production rate is very fast, and information is quickly sent from the pipeline and the client, which will cause accumulation on the server side. At the same time, since the producer (client) will close the file descriptor of the intermediate pipeline after producing specific data, it will also cause the server side to be closed accordingly. Therefore, it can be observed that the server side has not read all 30 pieces of data.

![](../assets/4.png)

**When the production rate is less than the consumption rate:**

As shown in the figure, when the production rate is less than the consumption rate, the cache maintained in the pc object on the server side is always at a low level. This is because the production rate is too slow, and the produced data will be consumed immediately, so there will not be too much data accumulation in the cache. In addition, because the server consumes faster, it can completely consume all the data sent by the client before the client closes the write-end file descriptor.

![](../assets/5.png)
3 changes: 3 additions & 0 deletions docs/exp.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 不同lambda组合实验

- [简体中文](./exp.md)
- [English](./exp-en.md)

在负指数分布中,如果参数越大,则表示 C++11 生成器生成的数字越小,这意味着 `sleep()` 的时间越小,表示事件越频繁。其次,我设置的逻辑是,server 端会在 client 关闭了写端描述符后,才会退出,因此,如果 client 已经发送完了所有信息,则会关闭中间管道的文件描述符,此时,无论 server 是否读完所有数据,server 都会直接退出。其三,我设置的逻辑是,client 的每一个 worker 端在发送 10 条消息(一共 30 条信息)后,自行退出(这个数字可以在配置文件更改)。

**为了方便观察,在server端,我打印了pc对象的cache缓存大小,用于观察和分析。**
Expand Down
29 changes: 29 additions & 0 deletions docs/reuse-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Framework reuse

- [简体中文](./reuse.md)
- [English](./reuse-en.md)

To reuse this framework, you need the contents in the `./Utils` and `./temp` directories.

Construct the `poll_control` object:

```cpp
poll_control* pc = new poll_control(worker,
callback, WORKER_NUMBER, worker_fds, connector_to_worker_fds, connector_to_connector_fd, lambda_arg, CLIENT);
pc->dispather();
```

The meaning of the parameters is as follows:
- `worker`: What the worker thread is going to do, the type is: `void* worker(void* args);` function pointer. After constructing the pc object, `WORKER_NUMBER` threads will be started to execute the content defined by the worker.
- `callback`: The callback to be executed by the multiplexing maintained in the pc object, type: `void callback(connection* conn)`
- `using callback_t = std::function<void(connection*)>;`
- `WORKER_NUMBER`: The number of worker threads, type is integer.
- `worker_fds`: The list of file descriptors for communicating with worker threads, the sequence size is the same as `WORKER_NUMBER`. Type: `std::vector<int>`.
- `connector_to_worker_fds`: The file descriptors for communication between epoll and worker in the pc object, which are also the file descriptors that epoll needs to care about, the sequence size is the same as `WORKER_NUMBER`. Type: `std::vector<int>`.
- `connector_to_connector_fd`: the external sock/fd that the epoll object cares about. For example, in this project, `connector_to_connector_fd` is the fd for pipe communication with another process, and its type is integer.
- `lambda_arg`: its type is double, and it is a parameter set specifically for this project. For details, see [readme](../README.md). If it is not needed, it can be deleted.
- `CLIENT`: a type specific to this project, which is an integer, indicating whether it is currently a client or a server. For details, see [readme](../README.md). If it is not needed, it can be deleted.

Note:
- The worker thread will be started after the constructor is called
- The multiplexing service needs to be manually called `dispather()` to forward before it can be started.
3 changes: 3 additions & 0 deletions docs/reuse.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 框架复用

- [简体中文](./reuse.md)
- [English](./reuse-en.md)

复用该框架,需要`./Utils``./temp`目录中的内容。

构造`poll_control`对象:
Expand Down

0 comments on commit 4f311de

Please sign in to comment.