다음 Testcase로 캐싱을 테스트 한 결과 성능이 향상되었습니다. 검색어의 예를 게시 할 수 있습니까?
public class ArangoDriverCacheTest {
private static final String COLLECTION_NAME = "unitTestCollection";
private static final String DATABASE_NAME = "unitTestDatabase";
private static ArangoConfigure configure;
private static ArangoDriver driver;
@BeforeClass
public static void setup() throws ArangoException {
configure = new ArangoConfigure();
configure.init();
driver = new ArangoDriver(configure);
// // create test database
try {
driver.createDatabase(DATABASE_NAME);
} catch (final ArangoException e) {
}
driver.setDefaultDatabase(DATABASE_NAME);
// create test collection
try {
driver.createCollection(COLLECTION_NAME);
} catch (final ArangoException e) {
}
driver.truncateCollection(COLLECTION_NAME);
// create some test data
for (int i = 0; i < 1000000; i++) {
final TestEntity value = new TestEntity("user_" + (i % 10), "desc" + (i % 10), i);
driver.createDocument(COLLECTION_NAME, value);
}
}
@AfterClass
public static void shutdown() {
try {
driver.deleteDatabase(DATABASE_NAME);
} catch (final ArangoException e) {
}
configure.shutdown();
}
private AqlQueryOptions createAqlQueryOptions(
final Boolean count,
final Integer batchSize,
final Boolean fullCount,
final Boolean cache) {
return new AqlQueryOptions().setCount(count).setBatchSize(batchSize).setFullCount(fullCount).setCache(cache);
}
@Test
public void test_withoutCache() throws ArangoException {
// set cache mode off
final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity();
properties.setMode("off");
driver.setQueryCacheProperties(properties);
exceuteQuery(false);
}
@Test
public void test_withCache() throws ArangoException {
// set cache mode on
final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity();
properties.setMode("on");
driver.setQueryCacheProperties(properties);
// set caching to true for the query
exceuteQuery(true);
}
private void exceuteQuery(final boolean cache) throws ArangoException {
final AqlQueryOptions aqlQueryOptions = createAqlQueryOptions(true, 1000, null, cache);
final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= @age SORT t.age RETURN t";
final Map<String, Object> bindVars = new MapBuilder().put("age", 90).get();
DocumentCursor<TestEntity> rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, TestEntity.class);
// first time, the query isn't cached
Assert.assertEquals(false, rs.isCached());
final long start = System.currentTimeMillis();
// query the cached value
rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, TestEntity.class);
Assert.assertEquals(cache, rs.isCached());
// load all results
rs.asEntityList();
final long time = System.currentTimeMillis() - start;
System.out.println(String.format("time with cache=%s: %sms", cache, time));
}
private static class TestEntity {
private final String user;
private final String desc;
private final Integer age;
public TestEntity(final String user, final String desc, final Integer age) {
super();
this.user = user;
this.desc = desc;
this.age = age;
}
}
}
답장을 보내 주셔서 감사합니다. 그러나이 테스트를 실행하는 동안 몇 가지 문제가 발생합니다. aqlQueryOptions.getCache()는 테스트에서 수동으로 다시 true로 설정하더라도 null을 반환합니다. 또한 두 경우 (캐시 사용 여부에 관계없이)의 결과는 거의 동일합니다. 거의 1-2 밀리 초 간격. –
내 코드가 바뀌 었습니다. 이제는 arango2.8/driver2.7과 호환됩니다. getter aqlQueryOptions.getCache()에는 버그가있어 wront 멤버를 반환합니다. 이 테스트를 실행하면 다음과 같은 결과가 발생합니다. 'time with cache = true : 7396ms' 'time with cache = false : 13703ms' – mpv1989
나를 위해 일합니다. 문제는 기본 쿼리 옵션의 일괄 처리 크기 때문이었습니다. 많은 수의 문서를 반환하는 쿼리에 대해 최적의 배치 크기를 제안 해 주시겠습니까? –