Search in sources :

Example 6 with User

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);
        }
    }
}
Also used : User(rpc.turbo.benchmark.bean.User) RandomAccess(java.util.RandomAccess)

Example 7 with 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;
}
Also used : LocalDateTime(java.time.LocalDateTime) User(rpc.turbo.benchmark.bean.User) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Example 8 with 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);
}
Also used : User(rpc.turbo.benchmark.bean.User) ArrayList(java.util.ArrayList)

Example 9 with User

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;
}
Also used : User(rpc.turbo.benchmark.bean.User) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 10 with 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;
}
Also used : User(rpc.turbo.benchmark.bean.User) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Aggregations

User (rpc.turbo.benchmark.bean.User)15 Benchmark (org.openjdk.jmh.annotations.Benchmark)7 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)7 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)7 ArrayList (java.util.ArrayList)3 ByteBufInput (io.protostuff.ByteBufInput)2 Kryo (com.esotericsoftware.kryo.Kryo)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 RandomAccess (java.util.RandomAccess)1 PostConstruct (javax.annotation.PostConstruct)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 Page (rpc.turbo.benchmark.bean.Page)1 UserService (rpc.turbo.benchmark.service.UserService)1 UserServiceServerImpl (rpc.turbo.benchmark.service.UserServiceServerImpl)1