Java 绝地武士(Redis)减速
我在redis中插入了大量文本,用于逐行存储频率。然而,绝地/redis的速度变慢了,在执行了一定数量的操作后,需要花费大量时间来执行操作,程序以错误结束: java.lang.OutOfMemoryError. 以下是我的主要测试文件: 公共类临时工{Java 绝地武士(Redis)减速,java,multithreading,redis,jedis,Java,Multithreading,Redis,Jedis,我在redis中插入了大量文本,用于逐行存储频率。然而,绝地/redis的速度变慢了,在执行了一定数量的操作后,需要花费大量时间来执行操作,程序以错误结束: java.lang.OutOfMemoryError. 以下是我的主要测试文件: 公共类临时工{ private ExecutorService executor; public temp() { executor = Executors.newFixedThreadPool(5); } public static void m
private ExecutorService executor;
public temp() {
executor = Executors.newFixedThreadPool(5);
}
public static void main(String[] args) {
temp ob = new temp();
System.out.println("starting");
for(long i =0;i<10000000;i++) {
if (i%10000 == 0) {
System.out.println(i);
}
String x = Integer.toString(new Random().nextInt());
ob.executor.submit(new Runner1("abra"+x));
ob.executor.submit(new Runner2("delhi"+x));
}
try {
if (ob.executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS)) {
System.out.println("completed");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
- 如果redis启动bgsave,您应该在redis.conf中禁用bgsave,通常在保存完成之前会有很大的延迟
- 您应该确保redis.conf中的maxmemory足够高。我猜您的实例已满
- 如果redis启动bgsave,您应该在redis.conf中禁用bgsave,通常在保存完成之前会有很大的延迟
- 您应该确保redis.conf中的maxmemory足够高。我猜您的实例已满
您没有完整地发布实际错误,我不是Java爱好者,但可能会为您保留一些答案。Redis不是内存不足的那个,您的Java进程是
你没有完整地发布实际的错误,我不是一个Java人,但可能会为你保留一些答案。内存使用量:23754992已用内存人类:22.65M已用内存人类:27152384已用内存人类:25.89M已用内存峰值:23754992已用内存峰值人类:22.65M总系统内存:8589934592总系统内存人类:8.00G已用_内存\u lua:37888已用内存\u lua\u人:37.00K最大内存:0最大内存\u人:0B最大内存\u策略:无受害者内存碎片率:1.14内存分配器:libc根据信息redis,内存未被大量使用。您可以运行“redis cli INFO”,然后启动java应用程序,看看命令是否立即得到处理。也许绝地武士正在批处理命令并导致暂停?#内存使用量#内存使用量#内存使用量#人:22.65M内存使用量(内存使用量)rss:27152384内存使用量(内存使用量)人:25.89M内存使用量(内存峰值)内存使用量(人:22.65M系统内存总量(内存:8589934592总量)tem_memory_human:8.00G used_memory_lua:37888 used_memory_lua_human:37.00K maxmemory:0 maxmemory_human:0B maxmemory_策略:noeviction mem_fragmentation_ratio:1.14 mem分配器:libc根据INFO redis,内存使用率不高。您可以运行“redis cli INFO”,然后启动java应用程序,看看是否立即处理了这些命令。可能是jedis正在批处理这些命令并导致暂停?这可能是因为jedis执行得非常慢,最终java会耗尽内存。这可能是因为jedis执行得非常慢,最终java会耗尽内存。
public class Runner1 implements Runnable {
//private static RedisClientUtil redisClient = null;
private String key;
private static Integer count = 0;
public Runner1(String key) {
this.key = key;
}
public void run() {
try {
ArrayList<ArrayList<Object>> cmd = new ArrayList<ArrayList<Object>>();
String offer_title = this.key + " this is thread1";
String offer_title_words[] = offer_title.split(" ");
for (String word : offer_title_words) {
// INCR the frequency in reddis
cmd.add(GenerateUtils.getArrayList("incrBy", "test"+word, 1));
}
List<Object> responses = RedisbenchmarkTest.getLocalhostJedisPool().executePipelinedAndReturnResponses(0,cmd);
cmd = null;
responses = null;
updateNumberOfRowsInserted();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private synchronized void updateNumberOfRowsInserted() {
//logging
count++;
if(count%10000==0)
System.out.println("Thread 1 : " + count);
}
}
public class Runner2 implements Runnable {
//private static RedisClientUtil redisClient = null;
private String key;
private static Integer count = 0;
public Runner2(String key) {
this.key = key;
}
public void run() {
try {
ArrayList<ArrayList<Object>> cmd = new ArrayList<ArrayList<Object>>();
String offer_title = this.key + " this is thread2";
String offer_title_words [] = offer_title.split(" ");
for (String word : offer_title_words) {
// INCR the category_word in reddis
cmd.add(GenerateUtils.getArrayList("incrBy","test1"+word,1));
} RedisbenchmarkTest.getLocalhostJedisPool().executePipelinedWithoutReturningResponses(0,cmd);
updateNumberOfRowsInserted();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private synchronized void updateNumberOfRowsInserted() {
//logging
count++;
if(count%10000==0)
System.out.println("Thread 2 : " + count);
}
}
public class RedisbenchmarkTest {
private static RedisClientUtil localhostJedisPool;
private static final JedisPoolConfig standardJedisPoolConfig = new JedisPoolConfig() {{
setMaxTotal(500);
setMaxIdle(20);
setMaxWaitMillis(500);
setTestOnBorrow(false);
setTestOnReturn(false);
}};
private static final int semiLowTimeout = 500;
static {
initialize();
}
public static void initialize() {
localhostJedisPool = new RedisClientUtil(
standardJedisPoolConfig
, "localhost"
, 6379
, semiLowTimeout
);
}
public static RedisClientUtil getLocalhostJedisPool() {
if (localhostJedisPool == null) {
initialize();
}
return localhostJedisPool;
}
}