Skip to content

Commit

Permalink
Add: Added deploy README.
Browse files Browse the repository at this point in the history
  • Loading branch information
chairc committed Nov 13, 2024
1 parent b974d8e commit b140b9f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
47 changes: 47 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
### Quick Deployment README

This document provides guidance on quickly deploying the project based on the provided source code, including both Web and Socket services. The relevant source code for deployment can be found in `deploy/deploy_server.py` and `deploy/deploy_socket.py`.

#### How It Works

`deploy_server.py` and `deploy_socket.py` are written using Flask for web services and Python's socket library for socket services, respectively.

- `deploy_server.py`: Creates a service using Flask, sets up `@app.route` routes to listen for requests, and performs deep learning inference upon receiving request data.

**Example Code**:

```python
# Main function
app.run(host=host, port=port, debug=False)

# Route
@app.route("/api/generate/df", methods=["POST"])
def generate_diffusion_model_api():
data = request.json
# Other code...
```

- `deploy_socket.py`: Creates a socket and binds it to a specified port. When a request is detected, a new thread is created to handle deep learning inference.

**Example Code**:

```python
# Create server socket
server_socket = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
# Get localhost name
host = socket.gethostname()
# Set port
port = 12345
# Bind the socket with localhost and port
server_socket.bind((host, port))
# Set the maximum number of listeners
server_socket.listen(5)
# Get the connection information of the local server
local_server_address = server_socket.getsockname()
```

#### Usage

Simply set the `host` and `port` parameters in both `deploy_server.py` and `deploy_socket.py`. Ensure that the ports used do not conflict with commonly used ports, and that the ports for these two services are different to avoid port conflicts.

These methods allow you to quickly deploy your online inference service and can also be used to rapidly deploy applications in **Docker or other containers**.
48 changes: 48 additions & 0 deletions deploy/README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
### 快速部署说明

本文件提供了如何根据提供的源代码对项目进行快速部署的指导,包括Web服务和Socket套接字服务。部署的相关源代码可以在 `deploy/deploy_server.py``deploy/deploy_socket.py` 中找到。

#### 如何运作

`deploy_server.py``deploy_socket.py` 分别依据Flask网络服务和Python的套接字包进行编写。

- `deploy_server.py` :通过Flask进行服务的创建,设置`@app.route`路由进行监听,获取到请求信息则进行深度学习的推理。

**此处为详细代码**

```python
# 主方法
app.run(host=host, port=port, debug=False)

# 路由
@app.route("/api/generate/df", methods=["POST"])
def generate_diffusion_model_api():
data = request.json
# 其它代码...
```

- `deploy_socket.py`:通过创建套接字并进行端口绑定,监听所绑定端口。若监听到请求,则创建一个新线程进行深度学习的推理。

**此处为详细代码**

```python
# 创建服务套接字
server_socket = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
# 获取本地host
host = socket.gethostname()
# 设置端口
port = 12345
# 绑定套接字和本地host与端口映射
server_socket.bind((host, port))
# 设置最大监听数量
server_socket.listen(5)
# 获取本地服务连接信息
local_server_address = server_socket.getsockname()
```


#### 使用方法

`deploy_server.py``deploy_socket.py` 分别设置`host``port`参数即可。注意,端口尽量与常用端口区分,同时两个服务的端口不要设置一样,以防端口占用。

上述方法可以快速的部署你的在线推理服务,也可在**Docker、或其它容器**中快速部署应用。

0 comments on commit b140b9f

Please sign in to comment.