Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void run() {
ping();
}
}
}, 1, 2, TimeUnit.MILLISECONDS);
}, 1, 1, TimeUnit.MILLISECONDS);
}
LOGGER.info("Start fast ping success.");
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.lts.example.benchmark;

import com.lts.core.commons.utils.DateUtils;
import com.lts.core.commons.utils.StringUtils;
import com.lts.core.domain.Job;
import com.lts.example.support.JobFinishedHandlerImpl;
import com.lts.example.support.MasterChangeListenerImpl;
import com.lts.example.support.MemoryStatus;
import com.lts.jobclient.JobClient;
import com.lts.jobclient.RetryJobClient;
import com.lts.jobclient.domain.Response;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
Expand Down Expand Up @@ -37,19 +38,24 @@ public static void main(String[] args) {

try {
// 休息1s 等待 连上JobTracker
Thread.sleep(1000);
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

MemoryStatus.print();

final AtomicLong num = new AtomicLong();
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

// 假设分了 20 个 partition
final long start = System.currentTimeMillis();

// 假设分了 100 个 partition
final int partition = 100;

for (int i = 0; i < 100; i++) {
final int totalSize = 1000000;

final AtomicInteger thread = new AtomicInteger(100);
for (int i = 0; i < thread.get(); i++) {

new Thread(new Runnable() {
@Override
Expand All @@ -65,7 +71,13 @@ public void run() {
if (!response.isSuccess()) {
System.out.println(response.getMsg());
} else {
num.incrementAndGet();
if (num.incrementAndGet() > totalSize) {
if (thread.decrementAndGet() == 0) {
MemoryStatus.print();
System.out.println("totalSize : " + totalSize + " , time: " + (System.currentTimeMillis() - start) + "ms");
break;
}
}
}
}
}
Expand All @@ -75,7 +87,7 @@ public void run() {
new Thread(new Runnable() {
@Override
public void run() {
while(true){
while (true) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.lts.example.support;

/**
* Created by hugui on 8/14/15.
*/
public class MemoryStatus {

public static void print() {
Runtime runtime = Runtime.getRuntime();
long freeMemory = runtime.freeMemory();
long totalMemory = runtime.totalMemory();
long maxMemory = runtime.maxMemory();
boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // 剩余空间小于2M报警
String msg = "Max:" + (maxMemory / 1024 / 1024) + "M, Total:"
+ (totalMemory / 1024 / 1024) + "M, Free:" + (freeMemory / 1024 / 1024)
+ "M, Use:" + ((totalMemory / 1024 / 1024) - (freeMemory / 1024 / 1024)) + "M";
System.out.println(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.lts.core.domain.Action;
import com.lts.core.domain.Job;
import com.lts.core.support.SystemClock;
import com.lts.tasktracker.Result;
import com.lts.tasktracker.runner.JobRunner;

Expand All @@ -12,10 +13,18 @@
*/
public class NoopJobRunner implements JobRunner {

static long start = 0;
static AtomicInteger num = new AtomicInteger(0);

public NoopJobRunner() {
if (start == 0) {
start = System.currentTimeMillis();
}
}

@Override
public Result run(Job job) throws Throwable {
System.out.println(num.incrementAndGet());
System.out.println(num.incrementAndGet() + " time : " + (SystemClock.now() - start) + "ms");
return new Result(Action.EXECUTE_SUCCESS);
}
}