Neo4j User Guide

Source: Internet
Author: User
Tags configuration settings finally block neo4j

Currently, the neo4j documentation is limited to official documents. This article will sort out the main official documents of neo4j for reference and the content will be updated continuously!


Start
  • Features
    1. Acid transactions
    2. High Availability
    3. Scalable to hundreds of millions of nodes and relationships
    4. High-speed Traversal
  • Deployment mode
      Single Instance Multiple instances
    Embedded Embeddedgraphdatabase Highlyavailablegraphdatabase
    Standalone Neo4j Server Not yet available
  • Maven Configuration
Add the following configuration to $ home/. m2/setting. xml:
<Profiles> <profile> <repositories> <repository> <ID> neo4j-public-repository </ID> <Name> publically available Maven 2 repository for neo4j </Name> <URL> http://m2.neo4j.org </ URL> <snapshots> <enabled> true </enabled> </snapshots> </Repository> </repositories> </profile> </profiles>
Add the following configuration to the project Pom. xml:
<Dependencies> <dependency> <groupid> Org. neo4j </groupid> <artifactid> neo4j </artifactid> <version> {neo4j. version }</version> </dependency> </dependencies>
  • Install

    • Windows

      1. Download from http://neo4j.org/
      2. Decompress the Installation File
      3. Configure environment variables: % neo4j_home % and % PATH %
      4. Install System Service: % neo4j_home %/bin/installneo4j. bat
      5. Startup: % neo4j_home %/bin/neo4j. bat
    • Linux is basically the same as windows
  • Keywords
    • Node: Node
    • Relationship: Relationship
    • Property: Property
    • Indexer: Indexer
    • Traverser: traversal Tool
  • Get started
    • One-minute wizard
    • Start wizard
    • Basic example
Neo4j Modeling
  • Design Guide
  • Domain Modeling
  • A specific example: from modeling to class design to coding
  • Code tips
    1. Wrap nodes: Pack Node
    2. Subreferences: Set a root sub-reference node (equivalent to namespace), and then create a node for your application domain under this node
  • Neoclipse
Rest API
Use curl for testing: curl-H http_header-X [get, post, put, delete]-D post_data your_url
-H http Header
-X http type
-D post data
Accept: Application/JSON -- acceptable response encoding format
Content-Type: Application/JSON -- content type format
For example:
Curl-H accept: Application/JSON-H Content-Type: Application/JSON-x get http: // localhost: 7474/DB/data/
Curl-H accept: Application/JSON-H Content-Type: Application/JSON-X Post-d '{"key1": "value1"} 'HTTP: // localhost: 7474/DB/data/node

More rest API Information

Index
  • Category

    1. Internal natural index: because it is equivalent to a tree structure (tree is also used as an index for databases, such as B), it is traversed by traverser.
    2. Use integrated indexes: such as Lucene
  • You can index nodes and links.
  • To update an index, you must first remove it before adding
  • If an index is cached by key, you can set the cache size: setcachecapacity
  • Old index mechanism
    • Indexservice
    • Do not instantiate multiple lucendexdexservice because it points internally to the same index data source.
    • Lucenefulltextindexservice and luceneindexservice direct to different index data sources.
    • Indexservice document
  • New index mechanism
    • Index document
Transactions
  • Transaction Overview
  • Nested transactions: there is only one high-level transaction, and all nested transactions are within the high-level transaction.
  • The transaction must be in the try finally block, and the transaction must display success ()
  • Deadlock
  • Do not make the transaction too small (I/O consumption) or too large (memory consumption)
  • Batch insert
    • Features:

      1. Used for data initialization and batch writing
      2. Non-transaction
      3. Non-thread security
      4. Better performance
      5. Possible upt Dataset
      6. During non-Batch inserts, the memory is allocated outside the heap. during batch inserts, the memory is allocated in the heap. Therefore, you must ensure sufficient heap size.
  • Spring transaction configuration: For details, see IMDB example transaction.
<tx:annotation-driven /><bean id="transactionManager"class="org.springframework.transaction.jta.JtaTransactionManager"><property name="transactionManager" ref="neo4jTransactionManagerService" /><property name="userTransaction" ref="neo4jUserTransactionService" /></bean><bean id="neo4jTransactionManagerService" class="org.neo4j.kernel.impl.transaction.SpringTransactionManager" /><bean id="neo4jUserTransactionService" class="org.neo4j.kernel.impl.transaction.UserTransactionImpl"><constructor-arg index="0" ref="graphDbService" /></bean>
@Transactionalpublic void newActors( final List<ActorData> actorList ){// code that operates on the graph}
Performance and performance considerations
  • CPU: 32-bit, 64-bit
  • Memory: at least 1 GB, 4 ~ recommended ~ 8 GB
  • Disk: At least SCSI and Eide. SSD and SATA are recommended.
  • Filesystem: supports fsync, fdatasync, at least ext3, and ext4 and ZFS are recommended.
  • Software: Java 1.6 +, OS: Windows, Linux, etc.
Performance adjustment (OS reserved memory + file mapping memory + JVM memory)
  1. Two aspects: caches and JVM

    1. Caches

      • File buffer cache (file mapping)

        • Low-level cache, operating system memory ing, use operating system features as much as possible
        • When a transaction is committed, the logic log is immediately fdatasync to disk, but the data file is not immediately flushed to the disk until the logic log is rotate, increasing the logic log size reduces the number of flush to disks (Wrapper can be used in the conf/neo4j-wrapper.conf. logfile. maxsize parameter configuration)
        • Prevent unnecessary page flush. Configure the OS to flush to the disk when the dirty page reaches a certain size (Linux OS parameter configuration)
        • Write delay until logical log rotation (sync, fsync, fdatasync)
        • Logical logs can be used for crash recovery
        • Fixed Length record
          • Nodestore 9 bytes
          • Relationshipstore 33 bytes
          • Propertystore 25 bytes (primitive attribute)
          • Stringstore 133 bytes (the pointer exists in propertystore. The specific data exists here, And 120bytes is valid)
          • Arraystore 133 bytes (the pointer exists in propertystore. The specific data exists here, And 120bytes is valid)
        • It can be configured to be cached in JVM memory or not in JVM memory.
        • Related configuration parameters
          1. Use_memory_mapped_buffers: True uses the operating system memory mapping, and false uses the heap memory for ing.
          2. Neostore. nodestore. DB. mapped_memory: node File Memory Mapping
          3. Neostore. relationshipstore. DB. mapped_memory: relational File Memory Mapping
          4. Neostore. propertystore. DB. mapped_memory: attribute File Memory Mapping
          5. Neostore. propertystore. DB. Strings. mapped_memory: string attribute File Memory Mapping
          6. Neostore. propertystore. DB. arrays. mapped_memory: array attribute File Memory Mapping
          7. String_block_size: String block size of the property type. The default value is 120 bytes (the block size cannot be changed after creation. If the size of a string is larger than the block size, the string will be distributed in multiple blocks, performance impact)
          8. Array_block_size: array block size of the property type. The default value is 120 bytes (the block size cannot be changed after creation, same as above)
          9. Dump_configuration: Dump configuration when started
        • In batch_inserter mode, you only need to consider node and relationship, because in this mode, generally the property will not be read after writing, and node and relationship will be read because they will save the attribute and so on.
      • Object Cache
        • High-level cache
        • Optimized storage for fast Traversal
        • Cached in the JVM heap
        • Delayed loading policy
        • LRU Policy
        • Related configuration parameters: cache_type: Soft (default) (softreference), weak (weakreference), and none (always in JVM, easy OOM)
    2. JVM
      • Parameters:-d32 or-d64 (32-bit or 64-bit),-server, memory-related parameters (memory size, generational ratio, thread stack size-XSS (All threads share ?)) , Garbage collector (CMS collector is recommended), memory dump is automatically generated during OOM
      • A large number of NiO packages, many out-of-heap memory allocation
      • To prevent page in or out (observe swap switching, do not leave the OS too small memory)
      • Consider the pause time (Pause Time)/throughput (throughput) of JVM)
      • NUMA structure: Version 1.6.0 update 18 Implementation,-XX: + usenuma
      • Size of each object in the heap
        1. Node: 688 bytes
        2. Relationship: 392 bytes
        3. Property: 232 bytes
        4. Primitive: 24 bytes
        5. String :( 64 + 2 * Len (string) bytes
        6. Relationships :???
    3. Write Performance: Transaction size (small transactions, many I/O transactions, large transactions, and many memory); Avoid dirty page flushed to disk unexpectedly (flush when flush is not required)
    4. For more configurations, see configuration settings
    5. For more performance information, see performance guide.
    Configuration
    • Neo4j-wrapper.conf: logfile-related configuration, JVM-related parameter configuration
    • Conf/neo4j-server.properties: neo4j parameter configuration file
      1. Org. neo4j. server. database. Location: DB location, relative to neo4j_home
      2. Org. neo4j. server. webserver. Port: port number. The default value is 7474.
      3. Org. neo4j. server. Webadmin. RRDB. Location: run the metrics information file. The default value is data/graph. DB/../RRD.
      4. Org. neo4j. server. Webadmin. Data. url: Rest API endpoint URL, default/DB/data/
      5. Org. neo4j. server. Webadmin. Management. Uri: URL of the management interface. Default Value:/DB/manage/
      6. Org. neo4j. server. DB. tuning. properties: Specifies the performance parameter configuration file. The default value is CONF/neo4j. properties.
    • Conf/neo4j. properties: low-level parameter configuration file of neo4j
    • Conf/log4j. properties: log4j configuration file
    • Conf/coord-wrapper.conf: Ha node STARTUP configuration
    • Conf/coord. cfg: zookeeper configuration of the HA Node
    Neo4j high availability deployment
    • Neo4j-ha Structural Diagram
    • Function
      1. Fault-tolerant
      2. Horizontally Scaling
      3. Slave can be written, synchronized to the master at the same time, and asynchronously synchronized to other slave; write to the master will be asynchronously synchronized to the slave
    • Use Apache zookeeper to maintain status information between nodes
    • Ha configuration parameters
      1. Ha. machine_id: Server ID
      2. Ha. SERVER: Host and port of the master
      3. Ha. zoo_keeper_servers: zookeeper connection, separated by commas
      4. Ha. pull_interval: The interval at which slave pulls data from the master.
    • For more information, see neo4j_ha_cluster.
    • Example: Examples
    Neo4j Shell
    • Add the configuration file: enable_remote_shell = true (default port: 1337) or enable_remote_shell = Port = 1331 (specified port)
    • Neo4j-shell-host-Port
    • Man can search for commands. For specific command parameters, man
    Neo4j backup
    • Parameter: keep_logical_logs: True
    Neo4j monitoring
    • Monitoring, see Monitor
    Neo4j security trouble shooting
    1. All APIs in neo4j are thread-safe, so no additional synchronization is required. Can the performance of the APIs in the serial mode be satisfactory?
    Related Documents
    • Neo4j-manual-stable.pdf
    • Related wiki documents
    • Stackoverflow Problems

     

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.