代码之家  ›  专栏  ›  技术社区  ›  Konrad Höffner

virtuoso sparql查询在javascript获取时速度慢

  •  1
  • Konrad Höffner  · 技术社区  · 7 年前

    当我在浏览器上执行sparql查询或 curl ,它比在同一个浏览器中使用javascript fetch快得多。例如, select * {?s ?p ?o.} 在dbpedia上,浏览器需要400-1000毫秒,使用javascript获取需要几秒钟。在这两种情况下,行数都被限制为10000(否则完整的dbpedia将太大)。这不仅限于dbpedia,它也发生在我们自己的sparql端点上,它包含大约100k个三元组。我使用的是FirefoxDeveloperEdition65.0B3(64位)。如何获得相同的性能或至少使用类似的性能? fetch ?要执行mwe,需要绕过cors规则。

    <!DOCTYPE html>
    <html>
    <head><meta charset="utf-8"></head>
    <body>
      <script>
    	const ENDPOINT = "http://dbpedia.org/sparql"
    	const GRAPH = "http://dbpedia.org";
    
    	function sparql(endpoint, graph, query)
    	{
    	  const url = endpoint +
    	  '?query=' + encodeURIComponent(query) +
    	  '&format=json'+
    	  '&default-graph-uri=' + encodeURIComponent(graph);
    	  return fetch(url);
    	}
      const query = "select * {?s ?p ?o.}";
    	sparql(ENDPOINT,GRAPH,query);
      </script>
    </body>
    </html>

    Network Tab of the MWE Network Tab of the query URL in Firefox

    1 回复  |  直到 7 年前
        1
  •  1
  •   TallTed    7 年前

    查看请求头中的差异(尤其是,可能不仅如此 Accept: */* VS Accept: text/html,application/xhtml..., */*;q=0.8 )

    我相信如果你 JS/fetch() request headers 与浏览器相同,您会发现响应时间将匹配。