Skip to content

Commit 40af5e5

Browse files
committed
Optimized HproseTcpClient and HproseTcpServer.
More fast and robust than before.
1 parent 263d377 commit 40af5e5

File tree

10 files changed

+176
-168
lines changed

10 files changed

+176
-168
lines changed

example/tcphelloexam/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.hprose</groupId>
55
<artifactId>tcphelloexam</artifactId>
6-
<version>1.5.0</version>
6+
<version>1.6.1</version>
77
<packaging>jar</packaging>
88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -15,7 +15,7 @@
1515
<dependency>
1616
<groupId>org.hprose</groupId>
1717
<artifactId>hprose-java</artifactId>
18-
<version>1.6.0-beta5</version>
18+
<version>1.6.1</version>
1919
</dependency>
2020
</dependencies>
2121
</project>

example/tcphelloexam/src/main/java/hprose/tcphelloexam/TCPHelloClient.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@
1010
public class TCPHelloClient {
1111
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
1212
System.out.println("START");
13+
HproseTcpClient.setReactorThreads(2);
1314
long start = System.currentTimeMillis();
14-
int threadNumber = 10;
15+
int threadNumber = 8;
16+
final int roundNumber = 125000;
1517
Thread[] threads = new Thread[threadNumber];
18+
final HproseTcpClient client = new HproseTcpClient("tcp://localhost:4321");
19+
client.setFullDuplex(true);
20+
client.setMaxPoolSize(2);
1621
for (int i = 0; i < threadNumber; i++) {
1722
threads[i] = new Thread() {
1823
@Override
1924
public void run() {
2025
try {
21-
HproseTcpClient client = new HproseTcpClient("tcp://localhost:4321");
22-
client.setFullDuplex(true);
23-
client.setMaxPoolSize(1);
24-
for (int i = 0; i < 100000; i++) {
26+
for (int i = 0; i < roundNumber; i++) {
2527
client.invoke("hello", new Object[] {"World"});
2628
}
27-
client.close();
2829
} catch (IOException ex) {
2930
Logger.getLogger(TCPHelloClient.class.getName()).log(Level.SEVERE, null, ex);
3031
}
@@ -36,8 +37,8 @@ public void run() {
3637
threads[i].join();
3738
}
3839
long end = System.currentTimeMillis();
39-
System.out.println(end - start);
40-
HproseTcpClient client = new HproseTcpClient("tcp://localhost:4321");
40+
System.out.println("总耗时: " + (end - start));
41+
System.out.println(((threadNumber * roundNumber) * 1000/(end - start)) + " QPS");
4142
start = System.currentTimeMillis();
4243
for (int i = 0; i < 10; i++) {
4344
client.invoke("hello", new Object[] {"World"}, new HproseCallback1<String>() {

example/tcphelloexam/src/main/java/hprose/tcphelloexam/TCPHelloServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static String hello(String name) {
1010
}
1111
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
1212
HproseTcpServer server = new HproseTcpServer("tcp://localhost:4321");
13+
server.setReactorThreads(2);
1314
/*
1415
server.addFilter(new HproseFilter() {
1516
public String getString(ByteBuffer buffer) {

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.hprose</groupId>
55
<artifactId>hprose-java</artifactId>
6-
<version>1.6.0</version>
6+
<version>1.6.1</version>
77
<name>Hprose for Java</name>
88
<description>Hprose is a High Performance Remote Object Service Engine.
99

@@ -49,7 +49,7 @@
4949
<connection>scm:git:https://github.com/hprose/hprose-java.git</connection>
5050
<developerConnection>scm:git:https://github.com/hprose/hprose-java.git</developerConnection>
5151
<url>https://github.com/hprose/hprose-java</url>
52-
<tag>v1.6.0</tag>
52+
<tag>v1.6.1</tag>
5353
</scm>
5454
<developers>
5555
<developer>

0 commit comments

Comments
 (0)