11 Replies Latest reply on May 24, 2013 10:31 PM by martani

    Performance issues with Jena Adapter


      I am running the following query using Jena Adapater
      SELECT * WHERE {
         :g :hasNode   ?node .
         OPTIONAL {
             ?node    :location   ?loc .
      I am expecting this to get translated to a single sdo_rdf_match+ query, however the log messages show that there is 1 sdo_rdf_match+ query issued to get the results of the *:g :hasNode ?node* part, and for each fetched result, another sdo_rdf_match+ query is issued.

      The master query:
      Final clause = SELECT ... FROM table(sdo_rdf_match('(<..#g> <..#hasNode> ?node)', sdo_rdf_models('model'), ...,'  ALLOW_DUP=T '))
      The inner queries issued for optional look like:
      Final clause = SELECT ... FROM table(sdo_rdf_match('(<..#MyNode1> <..#location> ?loc)', sdo_rdf_models('model'), ...,'  ALLOW_DUP=T '))
      Final clause = SELECT ... FROM table(sdo_rdf_match('(<..#MyNode2> <..#location> ?loc)', sdo_rdf_models('model'), ...,'  ALLOW_DUP=T '))
      (hundreds more...)
      This takes like 10 seconds to execute, however, with a single SEM_MATCH+ call of the above SPARQL query, it takes less than a second.

      Am I missing any special setup to make this work as expected?
        • 1. Re: Performance issues with Jena Adapter

          It should be just one SQL query and there is no special configuration needed. What is the DB version in this case?


          Zhe Wu
          • 2. Re: Performance issues with Jena Adapter

            I am using Oracle Database

            But I think I figured it out. Setting S2S to false as a system property solved this. In the documentation [1] however, it is mentioned that the option S2S equals to true (enabled by default for all SPARQL queries) should lead to better results usually.
            Properties props = System.getProperties();
            props.setProperty("oracle.spatial.rdf.client.jena.defaultS2S", "false");
            http://docs.oracle.com/cd/E11882_01/appdev.112/e11828/sem_jena.htm - Section 7.6.4 Additional Query Options.
            • 3. Re: Performance issues with Jena Adapter
              Hi Martani,

              S2S is an optimization that is good for performance. In this case, it seems that there was something wrong in translating
              SEM_MATCH to SQL or there was something wrong in executing the generated SQL. Either way is quite odd given
              the simplicity of the query.

              Please cut & paste below the full SPARQL query (including prefix definitions), and the code snippet that you use to
              construct either GraphOracleSem or DatasetGraphOracleSem.


              Zhe Wu
              • 4. Re: Performance issues with Jena Adapter

                This is the SPARQL query, it is a little complicated than what I've posted earlier:
                PREFIX    rdfs:                 <http://www.w3.org/2000/01/rdf-schema#>
                PREFIX    vcard:                <http://www.w3.org/2006/vcard/>
                PREFIX    prefix1:              <http://www.prefix1.com/prefix1/>
                PREFIX    prefix2:              <http://www.science.uva.nl/research/sne/prefix2/>
                PREFIX    :                     <http://www.defaultpref.com/>
                SELECT * WHERE {
                   :g        prefix1:hasNode     ?node .
                   ?node   prefix2:location     ?loc .
                   ?loc        rdfs:label          ?label .
                   OPTIONAL {
                       ?centered    rdfs:label          ?label .
                       :node1       prefix1:isCenter     ?centered .
                   FILTER ( !BOUND(?centered) ) .
                   ?loc        vcard:locality        ?locality .
                   OPTIONAL {
                       ?loc     vcard:region        ?region .
                   OPTIONAL {
                       ?loc   vcard:powser       ?power .
                   FILTER ( !REGEX( STR(?label), "^TOOL" ) ) .
                And the code I am using to execute the query:
                OracleConnection conn = ...
                Oracle oracle = new Oracle(conn);
                ModelOracleSem model = ModelOracleSem.createOracleSemModel(oracle, "MODEL");
                Query query = QueryFactory.create(sparqlQuery, Syntax.syntaxSPARQL_11);
                QueryExecution qexec = QueryExecutionFactory.create(query, model);
                ResultSet results = qexec.execSelect();
                When I use S2S=false in the ORACLE_SEM_FS_NS, the request is executed as expected, but when I omit it (or set it to true), the behavior described in the first message if reproduced.
                • 5. Re: Performance issues with Jena Adapter

                  Thanks for the query. I constructed the following test RDF data using the prefixes info and the query body.

                  % cat ./tests/forum_2539425.nt
                  <http://www.defaultpref.com/g> <http://www.prefix1.com/prefix1/hasNode> <urn:node> .
                  <urn:node> <http://www.science.uva.nl/research/sne/prefix2/location> <urn:loc> .
                  <urn:loc> <http://www.w3.org/2000/01/rdf-schema#label> "label" .
                  <urn:loc> <http://www.w3.org/2000/01/rdf-schema#label> "1TOOL" .
                  <http://www.defaultpref.com/node1> <http://www.prefix1.com/prefix1/isCenter> <urn:centered> .
                  <urn:loc> <http://www.w3.org/2006/vcard/locality> <urn:locality> .
                  <urn:loc> <http://www.w3.org/2006/vcard/region> <urn:region> .
                  <urn:loc> <http://www.w3.org/2006/vcard/powser> <urn:powser> .

                  Then I run the same SPARQL query (in trace mode) and everything works fine. I noticed
                  one SEM_MATCH query being translated into a single SQL which was then executed successfully.

                  Could you re-enable the S2S and add the following to your SPARQL query and run it again?

                  PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#no_fall_back>


                  Zhe Wu
                  • 6. Re: Performance issues with Jena Adapter
                    I am getting an exception with no_fall_back.
                    com.hp.hpl.jena.shared.JenaException: Unexpected SQLException 
                         at oracle.spatial.rdf.client.jena.OracleRepeatApply.nextStage(OracleRepeatApply.java:1076)
                         at com.hp.hpl.jena.sparql.engine.iterator.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java)
                         at com.hp.hpl.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java)
                         at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java)
                         at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java)
                         at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java)
                         at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java)
                         at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java)
                         at com.hp.hpl.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java)
                         at com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(ResultSetMem.java)
                         at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java)
                         at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:116)
                         at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:104)
                         at com.hp.hpl.jena.sparql.resultset.TextOutput.format(TextOutput.java:51)
                         at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:109)
                         at XercesTest.TestXSDNodes(XercesTest.java:163)
                         at XercesTest.Test(XercesTest.java:262)
                    Caused by: oracle.jdbc.driver.OracleSQLException: ORA-00942: table or view does not exist
                         at oracle.jdbc.driver.T2SConnection.check_error(T2SConnection.java)
                         at oracle.jdbc.driver.T2SPreparedStatement.checkError(T2SPreparedStatement.java)
                         at oracle.jdbc.driver.T2SPreparedStatement.describe_internal(T2SPreparedStatement.java)
                         at oracle.jdbc.driver.T2SPreparedStatement.executeForDescribe(T2SPreparedStatement.java)
                         at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java)
                         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java)
                         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java)
                         at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java)
                         at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java)
                         at oracle.spatial.rdf.client.jena.Oracle.executeQuery(Oracle.java)
                         at oracle.spatial.rdf.client.jena.OracleOpExecutor.buildSemIterator(OracleOpExecutor.java)
                         at oracle.spatial.rdf.client.jena.OracleRepeatApply.nextStage(OracleRepeatApply.java:1004)
                         ... 16 more
                    [XercesTest.java: Line 163] ResultSetFormatter.out(System.out, results, query);
                    • 7. Re: Performance issues with Jena Adapter

                      This is exactly why you observed the "slow" query. The S2S translated the SPARQL into a SQL and the execution failed. So we fall back to ARQ which uses many small queries to execute the original one.

                      Now we need to understand why this SQL fails with ORA-00942. Can you please create a new model
                      using Jena Adapter_ and run the same SPARQL query (with no_fall_back) against that new model?
                      You don't need to populate the model with any data.


                      Zhe Wu
                      • 8. Re: Performance issues with Jena Adapter

                        I have created a model using a non existing name like this:
                        ModelOracleSem model = ModelOracleSem.createOracleSemModel(oracle, "_model_non_existant");
                        Is this the correct way to do it?

                        Using this, I can see indeed the SQL query being generated. Does this mean something is missing from my model in the database?
                        • 9. Re: Performance issues with Jena Adapter
                          Hi back.

                          I think I get where the error is originating from.
                          The Oracle error ORA-00942 is indicating that the "Table or View Does Not Exist"; the table indicated in the SQL request is *"MDSYS"."RDFM_XYZ"* where XYZ is the string I pass as a model name when I construct my model with Jena Adapter.
                          ModelOracleSem model = ModelOracleSem.createOracleSemModel(oracle, "XYZ");
                          Now what's interesting is that the model XYZ is a virtual model, it has no associated TABLE_NAME in the view MDSYS.SEM_MODEL$ (and no view with the name MDSYS.RDFM_XYZ exists). It is rather a union of two other concrete models model_A and model_B which have respectively the associated views MDSYS.RDFM_model_A and MDSYS.RDFM_model_B.

                          I have tried to create a new virtual model using this code:
                          oracle.executeCall("begin sem_apis.create_virtual_model('model_vm_jena_adapter',sem_models('model_A', 'model_B'),null); end;");
                          And I can confirm that no view named MDSYS.RDFM_model_vm_jena_adapter or MDSYS.SEMM_model_vm_jena_adapter is created.

                          So is that a bug the Jena Adapter is generating SQL to access a view that does not exist in the case of a virtual model, or is there a proper way to construct a ModelOracleSem from a virtual model?

                          • 10. Re: Performance issues with Jena Adapter

                            You should use Attachment API and set a "true" flag to indicate the use of virtual model.

                            String[] modelNames = {"model_B"};
                            String[] rulebaseNames = {};

                            Attachment attachment = Attachment.createInstance(modelNames, rulebaseNames,
                            InferenceMaintenanceMode.NO_UPDATE, QueryOptions.ALLOW_QUERY_VALID_AND_DUP);
                            GraphOracleSem graph = new GraphOracleSem(oracle, "model_A", attachment, true);


                            Zhe Wu
                            • 11. Re: Performance issues with Jena Adapter
                              Thank you, it works.

                              I'll let you know about the performance issues with S2S enabled/disabled once I conduct more experiments.