Skip to content
Snippets Groups Projects
Commit a16c8e53 authored by 项升's avatar 项升
Browse files

Add service module

parent 3402c411
No related branches found
No related tags found
No related merge requests found
......@@ -14,13 +14,12 @@
### Apache Dubbo Gateway
TBD
### 题目由来
传统的负载均衡场景为单调度器模式,即中心化负载均衡:调度器负责将新到的请求立即转发至多个后端服务器中的一个。随着分布式系统的发展,这种单调度器模式在扩展性和可靠性方面的问题也愈发严重。因此,设计和实现去中心化且性能优异的负载均衡是学术和工业界的共同需求。
## 赛题说明
按照题目提供的扩展接口,实现一套自适应负载均衡机制。要求能够具备以下能力:
......@@ -29,9 +28,13 @@
2. Provider 端能自动进行服务容量评估,当请求数量超过服务能力时,允许拒绝部分请求,以保证服务不过载。
3. 当请求速率高于所有的 Provider 服务效率之和时,允许 Gateway( Consumer ) 拒绝服务新到请求。
### 架构
TBD
![service_architect](assets/service-architect.png)
- Gateway 负责将请求转发至 Provider;
- Provider 处理请求返回响应;
- Provider 按照 CPU 核数和内存大小分为 Small、Medium、Large 三个规格;
- 选手需要设计实现 Gateway 选择 Provider 的 loadbalance 算法。
### 服务
......
assets/service-architect.png

16.4 KiB

......@@ -26,5 +26,6 @@
<modules>
<module>internal-dubbo</module>
<module>internal-gateway</module>
<module>service</module>
</modules>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>adaptive-loadbalance</artifactId>
<groupId>com.aliware.tianchi</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service</artifactId>
<packaging>pom</packaging>
<modules>
<module>service-api</module>
<module>service-consumer</module>
<module>service-provider</module>
</modules>
<dependencies>
<dependency>
<groupId>com.aliware.tianchi</groupId>
<artifactId>internal-dubbo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.aliware.tianchi</groupId>
<artifactId>internal-gateway</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>service</artifactId>
<groupId>com.aliware.tianchi</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-api</artifactId>
</project>
\ No newline at end of file
package com.aliware.tianchi;
/**
* @author guohaoice@gmail.com
*/
public interface HashInterface {
/**
* 计算给定字符串的 hash 值
* <li>
* <ol>接口的响应时间符合负指数分布 </ol>
* <ol>接口的并发度(允许同时调用的线程数)会随时间增加或减小,从而模拟生产环境可能的排队</ol>
* </li>
* @param input 要计算的字符串
* @return 字符串的 hash 值
*/
int hash(String input);
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>service</artifactId>
<groupId>com.aliware.tianchi</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-consumer</artifactId>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>service</artifactId>
<groupId>com.aliware.tianchi</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-provider</artifactId>
<dependencies>
<dependency>
<groupId>com.aliware.tianchi</groupId>
<artifactId>service-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.aliware.tianchi;
import java.util.concurrent.ThreadLocalRandom;
/**
* Hash service impl
*
* @author guohaoice@gmail.com
*/
public class HashServiceImpl implements HashInterface {
private long averageRTT;
private int maxConcurrency;
private String salt;
public HashServiceImpl(long averageRTT, int maxConcurrency, String salt) {
this.averageRTT = averageRTT;
this.maxConcurrency = maxConcurrency;
this.salt = salt;
}
@Override
public int hash(String input) {
long baseRtt = nextRTT();
try {
Thread.sleep(baseRtt);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return (input + salt).hashCode();
}
private long nextRTT() {
ThreadLocalRandom rng = ThreadLocalRandom.current();
double u = rng.nextDouble();
int x = 0;
double cdf = 0;
while (u >= cdf) {
x++;
cdf = 1 - Math.exp(-1.0 * 1 / averageRTT * x);
}
return x;
}
}
package com.aliware.tianchi;
/**
* @author guohaoice@gmail.com
*/
public interface HashInterface {
int hash(String input);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment