缓存的压力测试脚本

贴一段Coherence压力测试脚本,在不需要部署web应用的情况下,直接在命令行进行压力测试

测试脚本启动100个Thread(ParallelTreadCount),然后每个thread运行500次(2000次读和100次写).

这100个thread会直接压到集群的其中一个代理节点上(proxy),所以保证proxy的thread配置>100.

package coherencetest;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.ConfigurableCacheFactory;
import com.tangosol.net.DefaultConfigurableCacheFactory;
import com.tangosol.net.NamedCache;

 

public class CoherenceCachePut implements Runnable {
private final ClassLoader loader = null;
NamedCache cache;

static int m_loop=100;
static int ParallelTreadCount =100;


public CoherenceCachePut() {
super();
}



public void run() {

long threadid = Thread.currentThread().getId();
NamedCache cache;
cache = CacheFactory.getCache("POFSample");
String AA = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
String a = "AAA";

for (int j=0;j<500;j++) {
for (int i=0;i<1000;i++) {
a = (String)cache.get(i);
}

for (int i=0;i<100;i++) {
cache.put(100-i,a);
}

for (int i=0;i<1000;i++) {
a = (String)cache.get(i);
}

}
}



public CoherenceCachePut(int loop) {
this.m_loop = loop;

}

public static void main (String [] args) {

NamedCache cache;
cache = CacheFactory.getCache("POFSample");
String AA = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";


for (int i=0;i<1000;i++) {
cache.put (i, "CacheValue="+AA+i);
}

int loop;

loop=m_loop;
for(int i=0; i<ParallelTreadCount; i++)
{
new Thread(new CoherenceCachePut(loop)).start();
}
}

}

原文地址:https://www.cnblogs.com/ericnie/p/5938471.html