4

我有一个缓存,其中字符串作为键,TileKey(下面的类)作为值,我注意到当我执行查询(下面)时,性能几乎线性地受到缓存大小的影响,即使所有使用的字段在查询中被索引。

这是一个有代表性的基准测试——我对所有基准测试使用了相同的查询(如下)和相同的参数:查询在所有基准测试中返回(相同的)30 个条目

  • 查询 5350 个条目缓存耗时 6-7ms
  • 查询 10700 个条目缓存耗时 8-10 毫秒
  • 查询 48150 个条目缓存耗时 30-42 毫秒
  • 查询 96300 个条目缓存耗时 50-70 毫秒

我已经使用 8gb 单节点和 4gb 2 节点执行了基准测试,结果几乎相同(就查询速度与缓存大小而言)

我还尝试通过使用“时间”字段作为第一个组字段来使用 QuerySqlFieldGroup,它应该在所有基准测试中将结果集减少到只有 1000 个条目,我不确定这是 QuerySqlFieldGroup 的正确用法,因为我理解它应该主要用于缓存之间的连接查询。

我做错了什么还是这些是使用 Ignite 索引的预期查询性能?

代码 :

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());
}

缓存配置:

<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;
}
4

1 回答 1

5

我找到了问题,感谢 bobby_brew 引导我朝着正确的方向前进。

Ignite的索引示例不正确,存在一个未解决的问题。

我已将索引字段注释从

   @QuerySqlField(index = true)
   @QuerySqlField.Group(name = "idx1", order = x)

@QuerySqlField(index = true, orderedGroups = {@QuerySqlField.Group(name = "idx1", order = x)})

现在查询持续时间在所有场景中都是稳定的 2ms

于 2015-08-16T10:33:17.477 回答