1. bug fix : MemcachedServer.java

2. finishing code
This commit is contained in:
martji 2014-09-01 13:27:03 +08:00
parent 60aabd4747
commit 5f5626daf2
9 changed files with 52 additions and 35 deletions

View File

@ -27,23 +27,43 @@ public class MemcachedServer {
public static long time = 0;
private static JSONArray results = new JSONArray();
public static Boolean status = false;
public static Boolean initFlag = false;
public static void main(String[] args) {
MemcachedServer.run(new String[]{"10","1000","1000","64","0.8"});
}
@SuppressWarnings("rawtypes")
private static void initial(){
PropertyConfigurator.configure(ORIGINPATH + "log4j.properties");// ¼ÓÔØ.propertiesÎļþ
SockIOPool pool = SockIOPool.getInstance();
pool.setServers(serverlist);
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(50);
pool.setMaintSleep(10);
pool.setNagle(false);
pool.initialize();
startIndex = 0;
oldStats = new HashMap<String, Map>();
nodeStats = new JSONArray();
results = new JSONArray();
status = false;
initFlag = false;
}
public static void run(String[] args) {
init();
oldStats = getStats();
initial();
int threads = Integer.parseInt(args[0]);
int runs = Integer.parseInt(args[1]);
int Nums = Integer.parseInt(args[2]); // how many kilobytes
int size = Integer.parseInt(args[3]); // how many kilobytes
double rate = Double.parseDouble(args[4]); // Áд±ÈÀý
int Nums = Integer.parseInt(args[2]);
int size = Integer.parseInt(args[3]);
double rate = Double.parseDouble(args[4]);
threadCount = threads;
// get object to store
byte[] obj = new byte[size];
for (int i = 0; i < size; i++) {
obj[i] = '1';
@ -53,6 +73,10 @@ public class MemcachedServer {
for (int i = 0; i < Nums; i++) {
keys[i] = "" + i;
}
oldStats = getStats();
DatabaseCon.getInstance().start();
MemcachedServer.initFlag = true;
for (int i = 0; i < threads; i++) {
bench b = new bench(runs, Nums, i, value, keys, rate);
@ -65,37 +89,17 @@ public class MemcachedServer {
} catch (InterruptedException e) {
e.printStackTrace();
}
}
time = time/threads;
}
getCurrentStats();
System.out.println(nodeStats);
time = time/threads;
initFlag = false;
System.out.println("requestNumber: " + results.length());
recycle();
status = true;
}
@SuppressWarnings("rawtypes")
private static void init(){
PropertyConfigurator.configure(ORIGINPATH + "log4j.properties");// ¼ÓÔØ.propertiesÎļþ
// initialize the pool for memcache servers
SockIOPool pool = SockIOPool.getInstance();
pool.setServers(serverlist);
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(50);
pool.setMaintSleep(10);
pool.setNagle(false);
pool.initialize();
DatabaseCon.getInstance().start();
startIndex = 0;
oldStats = new HashMap<String, Map>();
results = new JSONArray();
status = false;
}
private static void recycle(){
SockIOPool pool = SockIOPool.getInstance();
pool.shutDown();

View File

@ -125,8 +125,8 @@ public class RMemcachedServer {
getStats();
DatabaseCon.getInstance().start();
RMemcachedServer.initFlag = true;
for (int i = 0; i < threads; i++) {
bench b = new bench(runs, Nums, i, value, keys, rate);
b.start();
@ -134,7 +134,7 @@ public class RMemcachedServer {
while (WebServerMain.threadCount != 0){
try {
Thread.sleep(10);
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray;
import dao.MemcachedServer;
import dao.RMemcachedServer;
@SuppressWarnings("serial")
@ -71,14 +72,26 @@ public class GetInfoServlet extends HttpServlet {
switch (type) {
case 5:{
System.out.println("Start Run!!!");
String[] args = new String[5];
final String[] args = new String[5];
for (int i = 1; i <= args.length; i++) {
args[i-1] = request.getParameter("para"+i);
System.out.print("I = " + args[i-1] + "; ");
}
System.out.println();
RMemcachedServer.run(args);
while (!RMemcachedServer.status) {
new Thread(new Runnable() {
@Override
public void run() {
RMemcachedServer.run(args);
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
MemcachedServer.run(args);
}
}).start();
while (!RMemcachedServer.status || !MemcachedServer.status) {
try {
Thread.sleep(10);
break;