Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add http_server and doc #1321

Merged
merged 18 commits into from
Aug 4, 2021
Merged

Conversation

HexToString
Copy link
Collaborator

@HexToString HexToString commented Jul 26, 2021

1、增加Server支持Http Response压缩的代码。
2、增加了Http文档说明。doc/HTTP_SERVICE_CN.md
3、增加了PythonHttpClient(与原有方式基本相同,支持Numpy,多层List,Tuple输入,支持模型加密,Req压缩 Response压缩)
4、增加了JavaHttpClient(与原有方式基本相同,支持Numpy,多层List,以及数组输入,支持模型加密,Req压缩 Response压缩)
5、修改了Proto结构以及相关的代码,使结构更清晰。Request->多个FeedVar(即Tensor)->{Tensor.data Tensor.name等}
6、给出了Python通过Http直接访问C++Server的示例,python/examples/fit_a_line/test_httpclient.py
7、给出了Java通过Http直接访问的示例。java/examples/src/main/java/PaddleServingClientExample.java
8、删除了MultiLangClient相关内容和示例。
9、删除了serve中Flask启动的代码。

其他相关工作:
1、Pipeline中仍有代码依赖于Flask和MultiLang,建议全部更换为Http直接访问。
2、示例中,--name方式启动的已失效,但有的示例是通过import WebService的方式使用Flask,建议全部干掉更换为直接访问。
3、C++封一个Client能够BRPC+HTTP

@paddle-bot-old
Copy link

Thanks for your contribution!

@@ -280,6 +280,7 @@ class PdsCodeGenerator : public CodeGenerator {
" baidu::rpc::ClosureGuard done_guard(done);\n"
" baidu::rpc::Controller* cntl = \n"
" static_cast<baidu::rpc::Controller*>(cntl_base);\n"
" cntl->set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认启用压缩,客户端不支持是否会存在问题?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不会,这是返回值压缩,只有当客户端设置了Accept-Encoding:gzip的时候才会将返回值进行压缩。

Comment on lines 124 to 142
#### Server端Response压缩

当Http请求头中设置了Accept-encoding: gzip时,Server端会尝试用gzip压缩Response的数据,“尝试“指的是压缩有可能不发生,条件有:

- 请求中没有设置Accept-encoding: gzip。

- body尺寸小于-http_body_compress_threshold指定的字节数,默认是512。gzip并不是一个很快的压缩算法,当body较小时,压缩增加的延时可能比网络传输省下的还多。当包较小时不做压缩可能是个更好的选项。

这时server总是会返回不压缩的结果。

如果使用curl,通常推荐使用--compressed参数来设置Response压缩,--compressed参数会自动地在http请求中设置Accept-encoding: gzip,并在收到压缩后的Response后自动解压,对于用户而言,整个压缩/解压过程就像透明的一样。
```shell
curl --data-binary @data.txt.gz -H'Content-Encoding: gzip' --compressed -XPOST http://127.0.0.1:9393/GeneralModelService/inference
```

若使用-H'Accept-encoding: gzip',收到的将是压缩后的Response,您需要手动解压。
```shell
curl --data-binary @data.txt.gz -H'Content-Encoding: gzip' -H'Accept-encoding: gzip' -XPOST http://127.0.0.1:9393/GeneralModelService/inference | gunzip
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

压缩性能收益有多大 压缩请求方式可能过于复杂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当数据量较小时,不建议压缩。
压缩的逻辑,目前已经在HttpClient中支持了,这种curl的方式只是示意并说明原理。
在HttpClient中只需要set_request_compress或者set_response_compress即可

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文档中可能有表述不清的地方,我更新一下。
--compressed = 设置请求头+自动解压。
一般而言,不推荐 单独设置请求头 + 手动解压
示例仅是为了说明原理,加上可以提供,验证。否则用户无法验证你的返回是否真的压缩了。

from . import serve
from . import version

__all__ = ["version", "server", "serve", "monitor", "rpc_service", "dag"]
__all__ = ["version", "server", "serve", "monitor", "dag"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前的rpc请求如何支持?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个rpc_service是之前的MultiLang,也就是GRPC->(BRPCClient)->BRPC-Server 的方式
目前是各种语言的Http请求->BRPC-Server.

TeslaZhao
TeslaZhao previously approved these changes Aug 4, 2021
Copy link
Collaborator

@TeslaZhao TeslaZhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

bjjwwang
bjjwwang previously approved these changes Aug 4, 2021
Copy link
Collaborator

@bjjwwang bjjwwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HexToString HexToString dismissed stale reviews from bjjwwang and TeslaZhao via 3880c04 August 4, 2021 06:29
@TeslaZhao TeslaZhao merged commit 544df7b into PaddlePaddle:develop Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants