Skip to content
Snippets Groups Projects
Commit 0266fcb0 authored by 潇洒's avatar 潇洒
Browse files

use cpu

parent f1ee0b6e
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,9 @@ public class CallbackListenerImpl implements CallbackListener {
static long memory_large = 3;
static long memory_medium = 2;
static long memory_small = 1;
static double cpu_large = 3.0;
static double cpu_medium = 2.0;
static double cpu_small = 1.0;
static short mask = 0;
@Override
......@@ -21,25 +24,24 @@ public class CallbackListenerImpl implements CallbackListener {
//System.out.println("receive msg from server :" + msg);
String[] rcvmsglist = msg.split(",");
if (rcvmsglist[0].equals("small")) {
memory_small = Long.parseLong(rcvmsglist[1]);
cpu_small = 100-Double.parseDouble(rcvmsglist[1]);
mask |= 0x001;
}
else if (rcvmsglist[0].equals("medium")) {
memory_medium = Long.parseLong(rcvmsglist[1]);
cpu_medium = 100-Double.parseDouble(rcvmsglist[1]);
mask |= 0x010;
}
else {
memory_large = Long.parseLong(rcvmsglist[1]);
cpu_large = 100-Double.parseDouble(rcvmsglist[1]);
mask |= 0x100;
}
if (mask == 0x111) {
long memory_sum = memory_large + memory_medium + memory_small;
double cpu_sum = cpu_large*6.5 + cpu_medium*4.5 + cpu_small*2.0;
//System.out.println(msg + " : " + memory_large + ',' + memory_medium + ',' + memory_small + " | " + memory_sum);
UserLoadBalance.weight_large = 6.0 * memory_large / memory_sum;
UserLoadBalance.weight_medium = 6.0 * memory_medium / memory_sum;
UserLoadBalance.weight_small = 6.0 * memory_small / memory_sum;
int a=0;
UserLoadBalance.weight_large = cpu_large*6.5 / cpu_sum;
UserLoadBalance.weight_medium = cpu_medium*4.5 / cpu_sum;
UserLoadBalance.weight_small = cpu_small*2.0 / cpu_sum;
//System.out.println( UserLoadBalance.weight_large +" "+ UserLoadBalance.weight_medium+" "+ UserLoadBalance.weight_small);
mask = 0x0;
}
......
......@@ -19,13 +19,13 @@ import java.util.concurrent.ThreadLocalRandom;
*/
public class UserLoadBalance implements LoadBalance {
static double weight_large = 3.0;
static double weight_medium = 2.0;
static double weight_small = 1.0;
static double weight_large = 6.5/13;
static double weight_medium = 4.5/13;
static double weight_small = 2.0/13;
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
double thread = ThreadLocalRandom.current().nextDouble(6.0);
double thread = ThreadLocalRandom.current().nextDouble(1.0);
int id = 2;
if (thread < weight_small) id = 0;
else if (thread < weight_small + weight_medium) id = 1;
......
......@@ -29,8 +29,8 @@ public class CallbackServiceImpl implements CallbackService {
//System.out.println("Server push " +generateStatusMessage() + " Mem="+Runtime.getRuntime().freeMemory());
for (Map.Entry<String, CallbackListener> entry : listeners.entrySet()) {
try {
//entry.getValue().receiveServerMsg(System.getProperty("quota") + " " + new Date().toString());
entry.getValue().receiveServerMsg(System.getProperty("quota") + "," + Runtime.getRuntime().freeMemory());
//entry.getValue().receiveServerMsg(System.getProperty("quota") + " " + new Date().toString());Runtime.getRuntime().freeMemory()
entry.getValue().receiveServerMsg(System.getProperty("quota") + "," + generateStatusMessage());
} catch (Throwable t1) {
listeners.remove(entry.getKey());
}
......@@ -45,8 +45,8 @@ public class CallbackServiceImpl implements CallbackService {
private String generateStatusMessage() {
try {
List<String> cpuLoadList = getProcessCpuLoad().stream().map(Object::toString).collect(Collectors.toList());
String cpuLoadString = String.join(",", cpuLoadList);
return "cpu=" + cpuLoadString;
//String cpuLoadString = String.join(",", cpuLoadList);
return "cpu=" + cpuLoadList[0] ;
}
catch(Exception ex) {
return "error";
......
......@@ -20,14 +20,14 @@ public class TestRequestLimiter implements RequestLimiter {
*/
@Override
public boolean tryAcquire(Request request, int activeTaskCount) {
//
if("small".equals(System.getProperty("quota"))){
if (activeTaskCount > 195) return false;
} else if("medium".equals(System.getProperty("quota"))){
if (activeTaskCount > 445) return false;
} else if("large".equals(System.getProperty("quota"))){
if (activeTaskCount > 645) return false;
}
// //
// if("small".equals(System.getProperty("quota"))){
// if (activeTaskCount > 198) return false;
// } else if("medium".equals(System.getProperty("quota"))){
// if (activeTaskCount > 448) return false;
// } else if("large".equals(System.getProperty("quota"))){
// if (activeTaskCount > 648) return false;
// }
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment