4

これは spring-data-redis を使用した最初のアプリケーションであり、概念をかなりよく理解していると思います (過去に RDBMS-es で JdbcTemplate を何度も使用しました)。ここで何が起こっている...

私が直面している問題は、(ValueOperations オブジェクトを使用して) get(key) 操作を行うたびに、接続が開閉され、約 1/10 秒の遅延が発生することです (これはサーバー コードなので、1/10セカンドは充実しています)。春の XML 構成は次のとおりです。

<!-- Redis DAO stuff -->
<bean
    id="jedisPoolConfig"
    class="redis.clients.jedis.JedisPoolConfig"
    p:testOnBorrow="true"
    p:testOnReturn="true"
    p:timeBetweenEvictionRunsMillis="60000"
    p:minIdle="2"
    p:maxTotal="30"
    p:maxIdle="10"
  />

<bean id="jedisConnectionFactory"
    class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
    p:host-name="${redis.url}"
    p:port="${redis.port}"
    p:database="0"
    p:use-pool="true"
    p:pool-config-ref="jedisPoolConfig"
/>

<bean id="stringRedisSerializer"
    class="org.springframework.data.redis.serializer.StringRedisSerializer"
/>

<bean id="redisTemplate"
    class="org.springframework.data.redis.core.RedisTemplate" 
    p:connection-factory-ref="jedisConnectionFactory"
    p:defaultSerializer-ref="stringRedisSerializer"
/>

関連するJavaコードは次のとおりです。

@Autowired
private RedisTemplate<String, String> template;
private ValueOperations<String, String> valOps;

@PostConstruct
public void init() {
    logger.debug("111111111111111111111111aaaaaaaaaaaaaaaaaaaaaaa");
    valOps = template.opsForValue();
}

public String getTestVal() {
    logger.debug("getTestVal() function called++++++++++++++++++++");
    Object testVal2 = valOps.get("akey");
    testVal2 = valOps.get("akey");
    testVal2 = valOps.get("akey");
    testVal2 = valOps.get("akey");
    testVal2 = valOps.get("akey");
    testVal2 = valOps.get("akey");

    logger.debug("TestVal2 returned from REdis: " + testVal2);

    return null;
}

したがって、同じキーの値が 6 回取得されます。表示されるログ出力は次のとおりです。

13:46:37.011 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - getTestVal() function called++++++++++++++++++++
13:46:37.014 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
13:46:37.344 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
13:46:37.416 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
13:46:37.543 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
13:46:37.616 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
13:46:37.742 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
13:46:37.812 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
13:46:37.940 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
13:46:38.003 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
13:46:38.128 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
13:46:38.201 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
13:46:38.337 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
13:46:38.414 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO -  TestVal2 returned from REdis: yo mama

接続プールの設定方法に関するドキュメントに従ったと思っていましたが、Redis などのパフォーマンス指向のプラットフォームを扱う場合、私が見ているこの遅延は予想できませんでした。

支援やヒントをお寄せいただきありがとうございます。

4

1 に答える 1

1

spring-data-redis-1.7.2.RELEASE に基づく

if(!isConnectionTransactional(conn, factory)) {
    if (log.isDebugEnabled()) {
        log.debug("Closing Redis Connection");
    }
    conn.close()
}

ログを見ると、205行目に「Closing Redis Connection」と表示されており、closeメソッドを呼び出して接続を閉じています。

connがRedisConnectionを実装していることがわかります。この場合、使用した実際のクラスはJedisConnectionです。

256 行目から始まるコードを参照してください。

public void close() throws DataAccessExeception {
    super.close();
    // return the connection to the pool
    if (pool != null) {
        ...balabala 
    }
}

接続がプールに戻ります。これで、RedisConnectionUtilsは常に、プールを使用した場合でも「Closing Redis Connection」というログを表示することがわかりました。

于 2017-09-12T09:09:19.810 に答える