forked from sofastack/sofa-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d0d8a8
commit 7fc2357
Showing
25 changed files
with
336 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
|
||
import com.alipay.sofa.rpc.client.ProviderInfo; | ||
import com.alipay.sofa.rpc.core.request.SofaRequest; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
|
@@ -31,6 +33,7 @@ | |
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
public class ConsistentHashLoadBalancerTest extends BaseLoadBalancerTest { | ||
|
||
@Test | ||
public void doSelect() throws Exception { | ||
|
||
|
@@ -53,8 +56,8 @@ public void doSelect() throws Exception { | |
cnt.put(port, cnt.get(port) + 1); | ||
} | ||
long end = System.currentTimeMillis(); | ||
System.out.println("elapsed" + (end - start) + "ms"); | ||
System.out.println("avg " + (end - start) * 1000 * 1000 / total + "ns"); | ||
LOGGER.info("elapsed" + (end - start) + "ms"); | ||
LOGGER.info("avg " + (end - start) * 1000 * 1000 / total + "ns"); | ||
|
||
int count = 0; | ||
for (int i = 0; i < size; i++) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
|
||
import com.alipay.sofa.rpc.client.ProviderInfo; | ||
import com.alipay.sofa.rpc.core.request.SofaRequest; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
|
@@ -31,6 +33,9 @@ | |
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
public class WeightRoundRobinLoadBalancerTest extends BaseLoadBalancerTest { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(WeightRoundRobinLoadBalancerTest.class); | ||
|
||
@Test | ||
public void doSelect() throws Exception { | ||
WeightRoundRobinLoadBalancer loadBalancer = new WeightRoundRobinLoadBalancer(null); | ||
|
@@ -51,8 +56,8 @@ public void doSelect() throws Exception { | |
cnt.put(port, cnt.get(port) + 1); | ||
} | ||
long end = System.currentTimeMillis(); | ||
System.out.println("elapsed" + (end - start) + "ms"); | ||
System.out.println("avg " + (end - start) * 1000 * 1000 / total + "ns"); | ||
LOGGER.info("elapsed" + (end - start) + "ms"); | ||
LOGGER.info("avg " + (end - start) * 1000 * 1000 / total + "ns"); | ||
|
||
int avg = total / size; | ||
for (int i = 0; i < size; i++) { | ||
|
@@ -73,8 +78,8 @@ public void doSelect() throws Exception { | |
cnt.put(port, cnt.get(port) + 1); | ||
} | ||
long end = System.currentTimeMillis(); | ||
System.out.println("elapsed" + (end - start) + "ms"); | ||
System.out.println("avg " + (end - start) * 1000 * 1000 / total + "ns"); | ||
LOGGER.info("elapsed" + (end - start) + "ms"); | ||
LOGGER.info("avg " + (end - start) * 1000 * 1000 / total + "ns"); | ||
|
||
Assert.assertTrue(cnt.get(9000) == 0); | ||
int count = 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
public class WeightRoundRobinLoadBalancerV2Test { | ||
public class WeightRoundRobinLoadBalancerV2Test extends BaseLoadBalancerTest { | ||
|
||
/** | ||
* 上次选择的服务器 | ||
|
@@ -131,7 +131,7 @@ public static void main(String args[]) { | |
|
||
for (int i = 0; i < 15; i++) { | ||
Server server = weightRoundRobin.getServer(); | ||
System.out.println("server " + server.getIp() + " weight=" + server.getWeight()); | ||
LOGGER.info("server " + server.getIp() + " weight=" + server.getWeight()); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
</appender> | ||
|
||
<root> | ||
<level value="DEBUG"/> | ||
<level value="INFO"/> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
</appender> | ||
|
||
<root> | ||
<level value="DEBUG"/> | ||
<level value="INFO"/> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
</appender> | ||
|
||
<root> | ||
<level value="DEBUG"/> | ||
<level value="INFO"/> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
</appender> | ||
|
||
<root> | ||
<level value="DEBUG"/> | ||
<level value="INFO"/> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
</appender> | ||
|
||
<root> | ||
<level value="DEBUG"/> | ||
<level value="INFO"/> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,20 @@ | |
*/ | ||
package com.alipay.sofa.rpc.transport.rest; | ||
|
||
import com.alipay.sofa.rpc.common.RpcConstants; | ||
import com.alipay.sofa.rpc.context.RpcInternalContext; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
import com.alipay.sofa.rpc.tracer.sofatracer.RestTracerAdapter; | ||
|
||
import javax.annotation.Priority; | ||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.ext.Provider; | ||
import java.io.IOException; | ||
|
||
/** | ||
* | ||
* @author <a href="mailto:[email protected]">zhanggeng</a> | ||
* @author <a href="mailto:[email protected]">liangen</a> | ||
*/ | ||
|
@@ -40,6 +42,15 @@ public class TraceClientRequestFilter implements ClientRequestFilter { | |
@Override | ||
public void filter(ClientRequestContext requestContext) throws IOException { | ||
try { | ||
|
||
if (RpcInternalContext.isAttachmentEnable()) { | ||
// 补充客户端request长度 | ||
RpcInternalContext context = RpcInternalContext.getContext(); | ||
context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, | ||
requestContext.getHeaderString(HttpHeaders.CONTENT_LENGTH)); | ||
|
||
} | ||
|
||
RestTracerAdapter.storeTracerInfo(requestContext); | ||
} catch (Exception e) { | ||
logger.error("the process of rest tracer client request occur error ", e); | ||
|
Oops, something went wrong.