我有vibe-d程序,被用作链接的代理。我使用mysql-本机连接到SQL。这是可行的,但服务在20-2分钟后在更高的流量下死亡。除了: core.exception.AssertError之外,我没有看到任何具体的错误。这让我想,如果一切都安排妥当的话。我没有找到任何关于如何设置这样一个项目的例子。
这是我的应用程序的一个非常简化的版本。这是连接到Vibe项目中的MySQL的正确方式吗?我在Proxyd类中创建一个mysql池,然后在lockConnection的每个操作中打开新的连接。
void main()
{
Proxyd proxy = new Proxyd(dbConfig);
auto settings = new HTTPServerSettings;
HTTPListener http_listener = listenHTTP(settings, proxy.getRouter());
runApplication();
}
class Proxyd
{
URLRouter router;
MySQLPool db_pool;
public:
this(Node dbConfig)
{
router = new URLRouter;
router.get("/link", &link);
db_pool = new MySQLPool(host,username,password,database,port);
}
private:
void link(HTTPServerRequest request, HTTPServerResponse response)
{
db = db_pool.lockConnection();
ResultRange rows = db.query("..")
}
}发布于 2022-09-27 09:41:12
我不太确定,但这可能是因为vibe.core.connectionpool不能在工作线程之间共享。https://github.com/vibe-d/vibe-core/blob/f19401bfbe3d689b8ff7d50a9aafdf9f52887083/source/vibe/core/connectionpool.d#L74
这将是工作。
MySQLPool pool; // per threads, on TLS.
static this() {
pool = new MySQLPool(...);https://stackoverflow.com/questions/73864909
复制相似问题