欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JanusGraph服务器模式之ConfiguredGraphFactory配置

程序员文章站 2024-01-19 13:25:58
...

ConfiguredGraphFactory配置模式使JanusGraph的服务器模式更为灵活,即可以在服务器运行中动态添加、修改、删除图配置。

实现方式是利用*管理方式,创建一个ConfigurationManagementGraph的图,管理所有业务的图。

一、配置properties

/path/to/janusgraph-0.5.2/conf/gremlin-server/gremlin-server-hbase-configurationgraph.properties

路径和名称根据实际情况修改

gremlin.graph=org.janusgraph.core.ConfiguredGraphFactory
storage.backend=hbase
graph.graphname=ConfigurationManagementGraph
storage.hostname=127.0.0.1

cache.db-cache = true
cache.db-cache-clean-wait = 20
cache.db-cache-time = 180000
cache.db-cache-size = 0.5

index.search.backend=elasticsearch
index.search.hostname=127.0.0.1:9200
index.search.elasticsearch.http.auth.type=basic
index.search.elasticsearch.http.auth.basic.username=admin
index.search.elasticsearch.http.auth.basic.password=admin

# 这个对建索引很关键,在我的环境中不配置会报错
graph.timestamps=MICRO 

二、配置yaml

/path/to/janusgraph-0.5.2/conf/gremlin-server/gremlin-server-ws-configurationgraph.yaml

路径和名称根据实际情况修改

host: 127.0.0.1
port: 8182
scriptEvaluationTimeout: 30000
channelizer: org.janusgraph.channelizers.JanusGraphWsAndHttpChannelizer
graphManager: org.janusgraph.graphdb.management.JanusGraphManager
graphs: {
  ConfigurationManagementGraph: conf/gremlin-server/gremlin-server-hbase-configurationgraph.properties
}
scriptEngines: {
  gremlin-groovy: {
    plugins: { org.janusgraph.graphdb.tinkerpop.plugin.JanusGraphGremlinPlugin: {},
               org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {},
               org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {},
               org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]},
               org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: []}}}}
serializers:
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
  # Older serialization versions for backwards compatibility:
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: {ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
processors:
  - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }}
  - { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }}
metrics: {
  consoleReporter: {enabled: true, interval: 180000},
  csvReporter: {enabled: true, interval: 180000, fileName: /tmp/gremlin-server-metrics.csv},
  jmxReporter: {enabled: true},
  slf4jReporter: {enabled: true, interval: 180000},
  gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST},
  graphiteReporter: {enabled: false, interval: 180000}}
maxInitialLineLength: 4096
maxHeaderSize: 8192
maxChunkSize: 8192
maxContentLength: 65536
maxAccumulationBufferComponents: 1024
resultIterationBatchSize: 64
writeBufferLowWaterMark: 32768
writeBufferHighWaterMark: 65536

三、启动

cd /path/to/janusgraph-0.5.2
bin/gremlin-server.sh conf/gremlin-server/gremlin-server-ws-configurationgraph.yaml

四、使用

bin/gremlin.sh
gremlin> :remote connect tinkerpop.server conf/remote.yaml session
gremlin> :remote console
gremlin> map = new HashMap<String, Object>();
gremlin> map.put("storage.backend", "hbase");
gremlin> map.put("storage.hostname", "127.0.0.1");
gremlin> map.put("storage.hbase.table", "graph1");
gremlin> map.put("graph.graphname", "graph1");
gremlin> map.put("graph.timestamps", "MICRO"); // 必须先配置,后期更新感觉无法用
gremlin> ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
// 在这个阶段只是创建了配置,底层HBASE中并没有创建对应的graph1这个表

gremlin> graph1 = ConfiguredGraphFactory.open("graph1");
// 此时需要等待20秒左右,查看HBASE会出现graph1这个表

gremlin> graph1_traversal = graph1.traversal();
// 执行到此处后,下次需要使用graph1 和 graph1_traversal 不需要像以下进行复制,可直接

gremlin> graph1
gremlin> graph1_traversal
gremlin> graph1_traversal.V().size();
==>0

五、参考文献

https://github.com/JanusGraph/janusgraph/blob/master/docs/basics/configured-graph-factory.md

相关标签: JanusGraph