Skip to content
Snippets Groups Projects
Commit e066494d authored by Aiolos's avatar Aiolos
Browse files

memory weight version

parent 372be0ec
No related branches found
No related tags found
No related merge requests found
......@@ -11,10 +11,25 @@ import org.apache.dubbo.rpc.listener.CallbackListener;
*
*/
public class CallbackListenerImpl implements CallbackListener {
static long memory_large = 3;
static long memory_medium = 2;
static long memory_small = 1;
@Override
public void receiveServerMsg(String msg) {
System.out.println("receive msg from server :" + msg);
String[] rcvmsglist = msg.split(",");
if (rcvmsglist[0].equals("small")) memory_small = Long.parseLong(rcvmsglist[1]);
else if (rcvmsglist[0].equals("medium")) memory_medium = Long.parseLong(rcvmsglist[1]);
else memory_large = Long.parseLong(rcvmsglist[1]);
long memory_sum = memory_large + memory_medium + memory_small;
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;
}
}
......@@ -19,11 +19,17 @@ 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;
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
int[] invoker_list = {0, 1, 1, 2, 2, 2};
int id = ThreadLocalRandom.current().nextInt(6);
//System.out.println("Send one request to " + invoker_list[id]);
return invokers.get(invoker_list[id]);
double thread = ThreadLocalRandom.current().nextDouble(6.0);
int id = 2;
if (thread < weight_small) id = 0;
else if (thread < weight_small + weight_medium) id = 1;
System.out.println(id + " | " + weight_large + ',' + weight_medium + ',' + weight_small);
return invokers.get(id);
}
}
......@@ -25,7 +25,8 @@ public class CallbackServiceImpl implements CallbackService {
if (!listeners.isEmpty()) {
for (Map.Entry<String, CallbackListener> entry : listeners.entrySet()) {
try {
entry.getValue().receiveServerMsg(System.getProperty("quota") + " " + new Date().toString());
//entry.getValue().receiveServerMsg(System.getProperty("quota") + " " + new Date().toString());
entry.getValue().receiveServerMsg(System.getProperty("quota") + "," + Runtime.getRuntime().freeMemory());
} catch (Throwable t1) {
listeners.remove(entry.getKey());
}
......
......@@ -20,6 +20,7 @@ public class TestRequestLimiter implements RequestLimiter {
*/
@Override
public boolean tryAcquire(Request request, int activeTaskCount) {
if (activeTaskCount > 2000) 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