给 GPT 的 Prompts
User
在 Golang 编程中经常会用到 Worker Pool 并发模式,一个高性能、功能完备、简单易用的 Worker Pool 程序应该包含哪些 features?
DevChat
一个高性能、功能完备、简单易用的 Worker Pool 程序在 Golang 编程中应该包含以下特性:
任务队列:Worker Pool 需要一个任务队列来存储待处理的任务。这个队列应该是线程安全的,可以支持多个 worker 同时从中取出任务。
动态调整 worker 数量:Worker Pool 应该能够根据任务的数量和系统的负载动态地增加或减少 worker 的数量。
优雅的关闭:当没有更多的任务需要处理,或者接收到关闭信号时,Worker Pool 应该能够优雅地关闭,即停止接收新的任务,等待所有已经开始的任务完成后再关闭。
错误处理:Worker Pool 应该能够处理任务执行过程中出现的错误,例如可以提供一个错误回调函数。
任务超时处理:Worker Pool 应该能够处理任务执行超时的情况,例如可以设置一个超时时间,如果任务在这个时间内没有完成,就认为任务失败。
任务优先级:Worker Pool 可以支持任务优先级,优先处理优先级高的任务。
任务结果获取:Worker Pool 应该提供一种方式来获取任务的结果,例如可以提供一个结果回调函数。
任务重试:对于失败的任务,Worker Pool 可以提供重试机制,例如可以设置重试次数和重试间隔。
任务进度跟踪:Worker Pool 可以提供任务进度跟踪,例如可以提供一个进度回调函数,或者提供一个方法来查询当前的任务进度。
并发控制:Worker Pool 应该能够控制并发的数量,防止系统过载。
User
我想要开发一个 Worker Pool 程序,项目名叫 GoPool,并将其开源到 GitHub。现在我需要你帮我编写一个英文的 README.md,里面需要包含你总结的这些特性。
DevChat
以下是一个基于你的要求的 README.md 文件的草稿:
GoPool
GoPool is a high-performance, feature-rich, and easy-to-use worker pool library for Golang. It is designed to manage and recycle a pool of goroutines to complete tasks concurrently, improving the efficiency and performance of your applications.
Features
Task Queue: GoPool uses a thread-safe task queue to store tasks waiting to be processed. Multiple workers can simultaneously fetch tasks from this queue.
Dynamic Worker Adjustment: GoPool can dynamically adjust the number of workers based on the number of tasks and system load.
Graceful Shutdown: GoPool can shut down gracefully. It stops accepting new tasks and waits for all ongoing tasks to complete before shutting down when there are no more tasks or a shutdown signal is received.
Error Handling: GoPool can handle errors that occur during task execution. For example, it can provide an error callback function.
Task Timeout Handling: GoPool can handle task execution timeouts. For example, it can set a timeout period, and if a task is not completed within this period, the task is considered failed.
Task Priority: GoPool supports task priority. Tasks with higher priority are processed first.
Task Result Retrieval: GoPool provides a way to retrieve task results. For example, it can provide a result callback function.
Task Retry: GoPool provides a retry mechanism for failed tasks. For example, it can set the number of retries and the retry interval.
Task Progress Tracking: GoPool provides task progress tracking. For example, it can provide a progress callback function or a method to query the current task progress.
Concurrency Control: GoPool can control the number of concurrent tasks to prevent system overload.
Installation
To install GoPool, use go get
:
go get -u github.com/yourusername/gopool
Usage
Here is a simple example of how to use GoPool:
// code example here
Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
License
GoPool is released under the MIT License. See LICENSE for details.
请根据你的实际项目情况修改这个 README.md 文件,例如你可能需要提供一个具体的使用示例,或者添加安装和贡献指南等。