use of rpc.turbo.benchmark.bean.User in project turbo-rpc by hank-whu.
the class UserPageSerializer method write.
@Override
public void write(ByteBuf byteBuf, Page<User> userPage) {
List<User> userList = userPage.getResult();
byteBuf.writeInt(userPage.getPageNo());
byteBuf.writeInt(userPage.getTotal());
byteBuf.writeInt(userList.size());
if (userList instanceof RandomAccess) {
for (int i = 0; i < userList.size(); i++) {
userSerializer.write(byteBuf, userList.get(i));
}
} else {
for (User user : userList) {
userSerializer.write(byteBuf, user);
}
}
}
use of rpc.turbo.benchmark.bean.User in project turbo-rpc by hank-whu.
the class UserSerializer method read.
@Override
public User read(ByteBuf byteBuf) {
long id = byteBuf.readLong();
String name = stringSerializer.read(byteBuf);
int sex = byteBuf.readInt();
LocalDate birthday = localDateSerializer.read(byteBuf);
String email = stringSerializer.read(byteBuf);
String mobile = stringSerializer.read(byteBuf);
String address = stringSerializer.read(byteBuf);
String icon = stringSerializer.read(byteBuf);
int size = byteBuf.readInt();
List<Integer> permissions = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
permissions.add(byteBuf.readInt());
}
int status = byteBuf.readInt();
LocalDateTime createTime = localDateTimeSerializer.read(byteBuf);
LocalDateTime updateTime = localDateTimeSerializer.read(byteBuf);
User user = new User();
user.setId(id);
user.setName(name);
user.setSex(sex);
user.setBirthday(birthday);
user.setEmail(email);
user.setMobile(mobile);
user.setAddress(address);
user.setIcon(icon);
user.setPermissions(permissions);
user.setStatus(status);
user.setCreateTime(createTime);
user.setUpdateTime(updateTime);
return user;
}
use of rpc.turbo.benchmark.bean.User in project turbo-rpc by hank-whu.
the class UserServiceServerImpl method listUser.
@Override
public CompletableFuture<Page<User>> listUser(int pageNo) {
List<User> userList = new ArrayList<>(15);
for (int i = 0; i < 15; i++) {
User user = new User();
user.setId(i);
user.setName("Doug Lea" + i);
user.setSex(1);
user.setBirthday(LocalDate.of(1968, 12, 8));
user.setEmail("dong.lea@gmail.com" + i);
user.setMobile("18612345678" + i);
user.setAddress("北京市 中关村 中关村大街1号 鼎好大厦 1605" + i);
user.setIcon("https://www.baidu.com/img/bd_logo1.png" + i);
user.setStatus(1);
user.setCreateTime(LocalDateTime.now());
user.setUpdateTime(user.getCreateTime());
List<Integer> permissions = new ArrayList<>(List.of(1, 2, 3, 4, 5, 6, 7, 8, 19, 88, 86, 89, 90, 91, 92));
user.setPermissions(permissions);
userList.add(user);
}
page = new Page<>();
page.setPageNo(pageNo);
page.setTotal(1000);
page.setResult(userList);
return CompletableFuture.completedFuture(page);
}
use of rpc.turbo.benchmark.bean.User in project turbo-rpc by hank-whu.
the class MapVsThreadLocalBenchmark method copyOnWriteArrayList.
@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public User copyOnWriteArrayList() {
if (userList.isEmpty()) {
synchronized (userList) {
if (userList.isEmpty()) {
for (int i = 0; i < 12345 + 1; i++) {
User user = userService.getUser(i).join();
userMap.put(i, user);
userConcurrentMap.put(i, user);
userList.add(user);
}
}
}
}
User user = userList.get(12345);
if (user != null) {
return user;
}
return user;
}
use of rpc.turbo.benchmark.bean.User in project turbo-rpc by hank-whu.
the class MapVsThreadLocalBenchmark method threadLocal.
@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public User threadLocal() {
User user = userThreadLocal.get();
if (user != null && user.getId() == 12345L) {
return user;
}
user = userService.getUser(12345L).join();
userThreadLocal.set(user);
return user;
}
Aggregations