apache / incubator-hugegraph

A graph database that supports more than 100+ billion data, high performance and scalability (Include OLTP Engine & REST-API & Backends)
https://hugegraph.apache.org
Apache License 2.0
2.63k stars 517 forks source link

期望hugegraph的connection改进为使用连接池的方式 #1194

Open HerovNL opened 4 years ago

HerovNL commented 4 years ago

Expected behavior 期望表现

(1)现有的hugegraph的session管理connection在空闲的情况下未及时得到释放,在一个backend数据库中加载多个graph的情况下,每个graph下面占用不少连接又不释放,多个graph将会消耗大量的连接资源,还要不停的重试连接可用性;建议直接引入DruidDataSource连接池; (2)Transaction与connection解耦:connection应该是ThreadLocal的,Transaction对应一系列的SQL或者操作,在运行态只被同一个线程从上到下从开始到执行完成,Transaction的起始时申请Connection放在本线程ThreadLocal中,中间使用Connection时例如根据SQL生成PreparedStatement、commit()之类从ThreadLocal可直接get到,相关的方法入参中不必每次再传递Connection参数,Transaction结束时释放connection退给连接池;

Actual behavior 实际表现

(1)现有的hugegraph的session管理connection在空闲的情况下未及时得到释放 (2)现有的hugegraph的事务与connection没有解耦

javeme commented 4 years ago

@HerovNL 感谢反馈,同时也欢迎贡献代码。

HerovNL commented 4 years ago

[cid:df4d99f8-89cd-4a17-8fff-c38f76501107] 使用连接池对接MySQL的参考思路: 1 多图动态加载:如果支持多图共用一个MySQL数据库连接信息(jdbcUrl+userName),可以在启动时从默认的图的配置文件例如hugegraph.properties(默认的schema为hugegraph)先建立DruidDataSource连接池,然后查询hugegraph.t_graph中读取多个graph信息,这多个graph都使用这个连接池,中间可以调用API动态增删graph;本邮件附件代码中不含此功能; 2 某个图使用MySQL时,通过DruidDataSource连接池处理连接: (1)初始化:通过MysqlProvider的prepareDataSource() (2)非线程绑定的Connection的申请:MysqlDataSource.getConnection(),例如对database/schema的创建、删除、是否存在,这类一般不支持回滚,connection为automCommit=true,通过try-with-resource管理连接的释放; (3)线程绑定的Connection的申请、释放:MysqlDataSource.getConnection4Thread()、MysqlDataSource.releaseConnection4Thread(),在StandardHugegraph的Txs创建或者MysqlSessions.session.open()时准备连接,中间执行SQL时使用线程已有连接,Txs事物提交成功或者回滚时、或session关闭时释放连接返还给连接池; (4)连接池的JDBC URL中不体现schema/database,需要在SQL语句中表名前面加schmea/database信息;


发件人: Jermy Li notifications@github.com 发送时间: 2020年9月29日 14:39 收件人: hugegraph/hugegraph hugegraph@noreply.github.com 抄送: Herov xc95144@hotmail.com; Mention mention@noreply.github.com 主题: Re: [hugegraph/hugegraph] 期望hugegraph的connection改进为使用连接池的方式 (#1194)

@HerovNLhttps://github.com/HerovNL 感谢反馈,同时也欢迎贡献代码。

― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/hugegraph/hugegraph/issues/1194#issuecomment-700484063, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH4HFALVA7YOUVYRZHLIPBDSIF6IRANCNFSM4RZKYJAA.

javeme commented 4 years ago

@HerovNL 感谢分享,如果提交代码话可以直接推Pull Request到Github。 贡献代码流程可参考:https://github.com/hugegraph/hugegraph/blob/master/CONTRIBUTING.md

dyhyao6 commented 3 years ago

[cid:df4d99f8-89cd-4a17-8fff-c38f76501107] 使用连接池对接MySQL的参考思路: 1 多图动态加载:如果支持多图共用一个MySQL数据库连接信息(jdbcUrl+userName),可以在启动时从默认的图的配置文件例如hugegraph.properties(默认的schema为hugegraph)先建立DruidDataSource连接池,然后查询hugegraph.t_graph中读取多个graph信息,这多个graph都使用这个连接池,中间可以调用API动态增删graph;本邮件附件代码中不含此功能; 2 某个图使用MySQL时,通过DruidDataSource连接池处理连接: (1)初始化:通过MysqlProvider的prepareDataSource() (2)非线程绑定的Connection的申请:MysqlDataSource.getConnection(),例如对database/schema的创建、删除、是否存在,这类一般不支持回滚,connection为automCommit=true,通过try-with-resource管理连接的释放; (3)线程绑定的Connection的申请、释放:MysqlDataSource.getConnection4Thread()、MysqlDataSource.releaseConnection4Thread(),在StandardHugegraph的Txs创建或者MysqlSessions.session.open()时准备连接,中间执行SQL时使用线程已有连接,Txs事物提交成功或者回滚时、或session关闭时释放连接返还给连接池; (4)连接池的JDBC URL中不体现schema/database,需要在SQL语句中表名前面加schmea/database信息; ____ 发件人: Jermy Li notifications@github.com 发送时间: 2020年9月29日 14:39 收件人: hugegraph/hugegraph hugegraph@noreply.github.com 抄送: Herov xc95144@hotmail.com; Mention mention@noreply.github.com 主题: Re: [hugegraph/hugegraph] 期望hugegraph的connection改进为使用连接池的方式 (#1194) @HerovNLhttps://github.com/HerovNL 感谢反馈,同时也欢迎贡献代码。 ― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<#1194 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH4HFALVA7YOUVYRZHLIPBDSIF6IRANCNFSM4RZKYJAA.

能分享一下如何实现动态增删图吗@HerovNL

HerovNL commented 3 years ago

(1)初始化加载多graph:为了保持兼容性,沿用现有的conf/gremlin-server.yaml及hugegraph.properties配置,系统启动时从hugegraph.properties中读取到后端数据库的连接配置,这个连接配置是后续所有graph共用的,从hugegraph.properties指定的数据库hugegraph中t_graph的表(graph,alias)中读取到graph列表,然后将此在内存中替换掉gremlin-server.yaml中graphs的配置项,每个xxxgraph需要参照hugegraph.properties生成对应的conf/xxxgraph.properties;注意:这个t_graph表没有的话则自动创建并添加第一条记录(hugegraph,hugegraph); (2)运行时增删graph:扩展GraphsAPI支持增删graph功能;增删xxxgraph时通过Java反射修改GremlinServer中的GraphManager、TraversalSource、Bindings中以及RestServer中GraphManager中的ConcurrentMap对象中xxxgraph的对应记录,新增graph时注意调用InitStore类中的方法检测后台数据是否已经准备好,没准备好的话需要初始化一下;删除graph时注意及时关闭graph;无论GremlinServer还是RestServer中涉及的Hugegraph对象都来源于HugeFactoryAuthProxy,那里还有个ConcurrentMap;

dyhyao6 commented 3 years ago

(1)初始化加载多graph:为了保持兼容性,沿用现有的conf/gremlin-server.yaml及hugegraph.properties配置,系统启动时从hugegraph.properties中读取到后端数据库的连接配置,这个连接配置是后续所有graph共用的,从hugegraph.properties指定的数据库hugegraph中t_graph的表(graph,alias)中读取到graph列表,然后将此在内存中替换掉gremlin-server.yaml中graphs的配置项,每个xxxgraph需要参照hugegraph.properties生成对应的conf/xxxgraph.properties;注意:这个t_graph表没有的话则自动创建并添加第一条记录(hugegraph,hugegraph); (2)运行时增删graph:扩展GraphsAPI支持增删graph功能;增删xxxgraph时通过Java反射修改GremlinServer中的GraphManager、TraversalSource、Bindings中以及RestServer中GraphManager中的ConcurrentMap对象中xxxgraph的对应记录,新增graph时注意调用InitStore类中的方法检测后台数据是否已经准备好,没准备好的话需要初始化一下;删除graph时注意及时关闭graph;无论GremlinServer还是RestServer中涉及的Hugegraph对象都来源于HugeFactoryAuthProxy,那里还有个ConcurrentMap;

非常感谢您的指导 @HerovNL ,可我能力弱,无法实现该思路,能分享一下代码吗?或者提交到项目里面,供大家分享使用,谢谢

HerovNL commented 3 years ago

近期工作的缘故,一直比较忙,没时间处理这个,我会找时间尽量提交