use*_*575 5 java caching nosql spymemcached couchbase
我正在使用特定于应用程序的 json 对象加载本地 Couchbase 实例。
相关代码是:
CouchbaseClient getCouchbaseClient()
{
List<URI> uris = new LinkedList<URI>();
uris.add(URI.create("http://localhost:8091/pools"));
CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
cfb.setFailureMode(FailureMode.Retry);
cfb.setMaxReconnectDelay(1500); // to enqueue an operation
cfb.setOpTimeout(10000); // wait up to 10 seconds for an operation to succeed
cfb.setOpQueueMaxBlockTime(5000); // wait up to 5 seconds when trying to
// enqueue an operation
return new CouchbaseClient(cfb.buildCouchbaseConnection(uris, "my-app-bucket", ""));
}
Run Code Online (Sandbox Code Playgroud)
存储条目的方法(我正在使用来自Bulk Load 和 Exponential Backoff 的建议):
void continuosSet(CouchbaseClient cache, String key, int exp, Object value, int tries)
{
OperationFuture<Boolean> result = null;
OperationStatus status = null;
int backoffexp = 0;
do
{
if (backoffexp > tries)
{
throw new RuntimeException(MessageFormat.format("Could not perform a set after {0} tries.", tries));
}
result = cache.set(key, exp, value);
try
{
if (result.get())
{
break;
}
else
{
status = result.getStatus();
LOG.warn(MessageFormat.format("Set failed with status \"{0}\" ... retrying.", status.getMessage()));
if (backoffexp > 0)
{
double backoffMillis = Math.pow(2, backoffexp);
backoffMillis = Math.min(1000, backoffMillis); // 1 sec max
Thread.sleep((int) backoffMillis);
LOG.warn("Backing off, tries so far: " + tries);
}
backoffexp++;
}
}
catch (ExecutionException e)
{
LOG.error("ExecutionException while doing set: " + e.getMessage());
}
catch (InterruptedException e)
{
LOG.error("InterruptedException while doing set: " + e.getMessage());
}
}
while (status != null && status.getMessage() != null && status.getMessage().indexOf("Temporary failure") > -1);
}
Run Code Online (Sandbox Code Playgroud)
当 continuosSet 方法调用大量对象来存储(单线程)时,例如
CouchbaseClient cache = getCouchbaseClient();
do
{
SerializableData data = queue.poll();
if (data != null)
{
final String key = data.getClass().getSimpleName() + data.getId();
continuosSet(cache, key, 0, gson.toJson(data, data.getClass()), 100);
...
Run Code Online (Sandbox Code Playgroud)
它在 result.get() 操作中的 continuosSet 方法内生成 CheckedOperationTimeoutException 。
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: 127.0.0.1/127.0.0.1:11210
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:160) ~[spymemcached-2.8.12.jar:2.8.12]
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:133) ~[spymemcached-2.8.12.jar:2.8.12]
Run Code Online (Sandbox Code Playgroud)
有人可以阐明如何克服并从这种情况中恢复过来吗?是否有关于如何在 Couchbase 的 Java 客户端中批量加载的好技术/解决方法?我已经探索了文档Performing a Bulk Set不幸的是 PHP Couchbase 客户端。
我怀疑您可能正在从没有那么多内存的命令行生成的 JVM 中运行它。如果是这种情况,您可能会遇到更长的 GC 暂停,这可能会导致您提到的超时。
我认为最好的办法是尝试一些事情。首先,将 -Xmx 参数提高到 JVM 以使用更多内存。查看超时是稍后发生还是消失。如果是这样,那么我对记忆的怀疑是正确的。
如果这不起作用,请提高 setOpTimeout() 并查看是否可以减少错误或使其消失。
另外,请确保您使用的是最新的客户端。
顺便说一句,我不认为这与批量加载直接相关。这可能是由于在批量加载期间消耗了大量资源而发生的,但看起来常规退避必须有效,否则您永远不会遇到它。
| 归档时间: |
|
| 查看次数: |
5851 次 |
| 最近记录: |