我有一个缓存字符串作为一个键和TileKey(下面的类)作为一个值,我注意到,当我执行一个查询(下面)的性能几乎线性地影响缓存大小,即使在查询中使用的所有字段都被索引。
这是一个代表性的基准测试-我使用了相同的查询(下面)与相同的参数为所有基准测试:查询在所有基准测试中返回(相同的)30个条目
- 查询5350项缓存花费6-7ms
- 查询10700项缓存花费8-10ms
- 查询48150项缓存耗时30-42ms
- 查询96300项缓存占用50-70ms
我用8gb单节点和4gb双节点执行了基准测试,结果几乎是一样的(就查询速度相对于缓存大小而言)
我还尝试使用QuerySqlFieldGroup通过使用"时间"字段作为第一组字段,它应该减少结果集到只有1000个条目在所有基准测试中,我不确定这是正确的使用QuerySqlFieldGroup从我的理解,它应该主要用于缓存之间的连接查询。
我做错了什么或这些是预期的查询性能使用点燃索引?
代码:String strQuery = "time = ? and zoom = ? and x >= ? and x <= ? and y >= ? and y <= ?";
SqlQuery<String, TileKey> query= new SqlQuery<String, TileKey>(TileKey.class, strQuery);
query.setArgs(time, zoom, xMin,xMax,yMin, yMax);
QueryCursor<Entry<String, TileKey>> tileKeyCursor = tileKeyCache.query(query);
Map<String, TileKey> tileKeyMap = new HashMap<String, TileKey>();
for (Entry<String, TileKey> p : keysCursor) {
tileKeyMap.put(p.getKey(), p.getValue());
}
Cache配置:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="KeysCache" />
<property name="cacheMode" value="PARTITIONED" />
<property name="atomicityMode" value="ATOMIC" />
<property name="backups" value="0" />
<property name="queryIndexEnabled" value="true"/>
<property name="indexedTypes">
<list>
<value>java.lang.String</value>
<value>org.ess.map.TileKey</value>
</list>
</property>
</bean>
类:@QueryGroupIndex.List(@QueryGroupIndex(name = "idx1"))
public class TileKey implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String id;
@QuerySqlField(index = true)
@QuerySqlField.Group(name = "idx1", order = 0)
private int time;
@QuerySqlField(index = true)
@QuerySqlField.Group(name = "idx1", order = 1)
private int zoom;
@QuerySqlField(index = true)
@QuerySqlField.Group(name = "idx1", order = 2)
private int x;
@QuerySqlField(index = true)
@QuerySqlField.Group(name = "idx1", order = 3)
private int y;
@QuerySqlField(index = true)
private boolean inCache;
}
我已经找到问题了,谢谢bobby_brew给我指明了正确的方向。
Ignite的索引示例是不正确的,这是一个公开的问题。
我已经从
更改了索引字段注释 @QuerySqlField(index = true)
@QuerySqlField.Group(name = "idx1", order = x)
@QuerySqlField(index = true, orderedGroups = {@QuerySqlField.Group(name = "idx1", order = x)})
,现在查询持续时间在所有场景下都是2ms