Skip to content

Performance issue with client side transaction management #1390

Closed

Description

@devcode100

ArcadeDB Version:

ArcadeDB Server version: 23.11.1

OS and JDK Version:

OS = Linux(ubuntu 22.04)
JDK version = 17
Artifacts:
arcadedb-gremlin = 23.12.1-SNAPSHOT
arcadedb-network = 23.12.1-SNAPSHOT

Expected behavior

Simple mutation logics within a transaction block, such as adding new vertex with ~3 properties should not take more than ~20ms in a database with existing record size of 1000 records.

Actual behavior

The simple mutation logic is taking 300ms.

Steps to reproduce

There are two implementation styles which will help to compare the performance issue.

  1. The mutation logic ran as below without explicitly starting transaction at client side.
    This implementation will commit transaction at server side.
    Performance: 10ms. This is an expected performance.
    Drawback: Unable to perform client side transaction management. In case of rollback due to client side exceptions, with this implementation is not possible.
       ArcadeGraph arcadeGraph = arcadeGraphFactory.get();
        GraphTraversalSource g = arcadeGraph.traversal();
        try {
            g.addV("Country").property("id", id).property("country", country).property("code", code).iterate();
        } catch (Exception e) {
            logger.debug("Exception: {}", e);
        } finally {
            arcadeGraph.close();
        }
  1. The mutation logic ran as below by starting transaction using arcadeGraph.tx().begin() and commit at client side:
        ArcadeGraph arcadeGraph = arcadeGraphFactory.get();
        GraphTraversalSource g = arcadeGraph.tx().begin();
        try {
            g.addV("Country").property("id", id).property("country", country).property("code", code).iterate();

            arcadeGraph.tx().commit();
        } catch (Exception e) {
            arcadeGraph.tx().rollback();
        } finally {
            arcadeGraph.close();
        }

Performance: 300ms. This is an issue.
But here full control of transaction is possible.

To summarize, the expectation is to have the latency of mutation logic to be at ~10-20ms, together with the ability to control transaction management at client side.

Activity

  1. self-assigned this
    on Dec 18, 2023
  2. added this to the 23.12.1 milestone on Dec 18, 2023
  3. lvca commented on Dec 18, 2023

    @lvca
    Member

    I've created 2 new tests in our test suite:

    @Test
      public void executeTraversalTxMgmt() {
        try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root",
            BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) {
          try (final ArcadeGraph graph = pool.get()) {
            for (int i = 0; i < 1000; i++) {
              GraphTraversalSource g = graph.tx().begin();
              g.addV("Country").property("id", i).property("country", "USA").property("code", i).iterate();
              g.tx().commit();
            }
    
            Assertions.assertEquals(1000, graph.traversal().V().hasLabel("Country").count().toList().get(0));
          }
        }
      }
    
      @Test
      public void executeTraversalNoTxMgmt() {
        try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root",
            BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) {
          try (final ArcadeGraph graph = pool.get()) {
            for (int i = 0; i < 1000; i++)
              graph.traversal().addV("Country").property("id", i).property("country", "USA").property("code", i).iterate();
          }
    
          try (final ArcadeGraph graph = pool.get()) {
            Assertions.assertEquals(1000, graph.traversal().V().hasLabel("Country").count().toList().get(0));
          }
        }
      }
    

    And the version that begin/commit a transaction per vertex, 1,000 times, it's a little slower than the one that executes 1,000 adds a vertex in the same transaction:

    • executeTraversalNoTxMgmt: 4.6 sec
    • executeTraversalTxMgmt: 5.4 sec

    How can I reproduce this issue? Could your issue be related to the client/server network?

    Could you please get the latest source and run the tests above under the class com.arcadedb.server.gremlin.RemoteGremlinFactoryIT?

  4. devcode100 commented on Dec 18, 2023

    @devcode100
    Author

    One of the key difference between the above Tests and the implementation I shared is that I use ArcadeGraphFactory as singleton and create ArcadeGraph instance for every request. The requests are concurrent and may not be always sequential.

  5. lvca commented on Dec 18, 2023

    @lvca
    Member

    I tested by getting a new graph every time, but since we have a pool now, the performance are identical to the previous tests. Trying to spin multiple threads

  6. lvca commented on Dec 18, 2023

    @lvca
    Member

    Tried multi threads, same time:

    @Test
      public void executeTraversalTxMgmtMultiThreads() throws InterruptedException {
        try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root",
            BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) {
    
          try (final ArcadeGraph graph = pool.get()) {
            graph.getDatabase().getSchema().createVertexType("Country");
          }
    
          final ExecutorService executorService = Executors.newFixedThreadPool(10);
    
          for (int i = 0; i < 1000; i++) {
            final int id = i;
            executorService.submit(() -> {
              try (final ArcadeGraph graph = pool.get()) {
                GraphTraversalSource g = graph.tx().begin();
                g.addV("Country").property("id", id).property("country", "USA").property("code", id).iterate();
                g.tx().commit();
              }
            });
          }
    
          executorService.shutdown();
          executorService.awaitTermination(60, TimeUnit.SECONDS);
    
          try (final ArcadeGraph graph = pool.get()) {
            Assertions.assertTrue(graph.traversal().V().hasLabel("Country").count().toList().get(0) > 800);
          }
        }
      }

    I think it could be the latency between client and server. How are they connected? LAN? Internet?

  7. devcode100 commented on Dec 18, 2023

    @devcode100
    Author

    Am using the same connection and setup for both the scenarios(10ms and 300ms code blocks run on same setup)and at this moment I can rule out bandwidth dependency.
    If you can follow the below *Steps to Replicate:

    • with a real remote connection
      Spin up new cloud VM(I use AWS EC2 - Ubuntu 22.04) specifically test on cloud VM and connect to it remotely from client. at least this is how I could replicate ]
    1. Auto assign public IP(machine is publicly assessable).
    2. Set up JDK 17
    3. Download latest distro: https://github.com/ArcadeData/arcadedb/releases/download/23.11.1/arcadedb-23.11.1.tar.gz
    4. Clone the repo: https://github.com/ArcadeData/arcadedb and use main branch to execute mvn clean install
    5. Replace the arcadedb-*.jars(11 jars) in the arcadedb server lib folder.
    6. Run the command from home dir to start the server:
      bin/server.sh -Darcadedb.server.plugins="GremlinServer:com.arcadedb.server.gremlin.GremlinServerPlugin"
    7. Configure java client to connect to the remote server using ArcadeGraphFactory(use the same 23.12.1-SNAPSHOT in pom.ml - client app.)

    Enabled logs. PF the trace for the mutation logic which took > ~300ms.
    Tx_perf_issue

    I tried to replicate in local[windows](follow step 3-7), am not getting the issue, Tx is fast.

    If you are not able to replicate even after following the above steps(similar) then I will wait for the next release to upgrade the server and maven libs without any manual artifact build and replacement, and will test it again.

    Note:-
    If the complete tx() is sum of below 3 network round trips, then its fair to have the latency as I mentioned and could be considered as working as expected. The ping latency is fairly high for the cloud VM's I use.

    • GraphTraversalSource g = graph.tx().begin(); // Network Round trip - 150ms
    • g.addV("Country").property("id", id).property("country", "USA").property("code", id).iterate(); // Network Round trip - 150ms
    • g.tx().commit(); // Network Round trip - 150ms
  8. lvca commented on Dec 18, 2023

    @lvca
    Member

    I found the reason. With the TX management, ArcadeDB is using the HTTP protocol and it's sending 3 HTTP commands for each cycle to the server:

    1. begin
    2. gremlin command to add a vertex
    3. commit

    With the non-TX management (the fast one), the client communicates with the Gremlin server by using the binary protocol + the transaction management is done on the server side.

    So the difference in speed is mainly for the 3 requests against 1. The 3 requests cannot be sent asynchronously because they are sequential begin/addV/commit. You pay the latency here of waiting for the 2 additional commands.

    About the HTTP vs Binary protocols, I don't think this makes a lot of difference.

  9. lvca commented on Dec 19, 2023

    @lvca
    Member

    Tried back with using only Gremlin, but this is the exception on the Gremlin side:

    java.lang.IllegalStateException: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource.traversal() is applicable for argument types: () values: []
    

    And this was the source:

    @Test
      public void executeTraversalTxMgmtBinary() throws InterruptedException {
        try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root",
            BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) {
    
          for (int i = 0; i < 1000; i++) {
            final int id = i;
            try (final ArcadeGraph graph = pool.get()) {
              GraphTraversalSource g = graph.traversal();
              g.tx().begin();
              g.addV("Country").property("id", id).property("country", "USA").property("code", id).iterate();
              g.tx().commit();
            }
          }
    
          try (final ArcadeGraph graph = pool.get()) {
            Assertions.assertEquals(1000, graph.traversal().V().hasLabel("Country").count().toList().get(0));
          }
        }
      }

    So I'm closing the issue, knowing that by using explicit TX control means involving 2 commands per vertex

  10. added
    wontfix
    on Dec 19, 2023
  11. added a commit that references this issue on Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

performancewontfix

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions