io.github.dzh:dimit-core

The Distributed Traffic Control System

License

License

GroupId

GroupId

io.github.dzh
ArtifactId

ArtifactId

dimit-core
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

The Distributed Traffic Control System

Download dimit-core

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.dzh/dimit-core/ -->
<dependency>
    <groupId>io.github.dzh</groupId>
    <artifactId>dimit-core</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.dzh/dimit-core/
implementation 'io.github.dzh:dimit-core:0.0.2'
// https://jarcasting.com/artifacts/io.github.dzh/dimit-core/
implementation ("io.github.dzh:dimit-core:0.0.2")
'io.github.dzh:dimit-core:jar:0.0.2'
<dependency org="io.github.dzh" name="dimit-core" rev="0.0.2">
  <artifact name="dimit-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.dzh', module='dimit-core', version='0.0.2')
)
libraryDependencies += "io.github.dzh" % "dimit-core" % "0.0.2"
[io.github.dzh/dimit-core "0.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
io.github.dzh : dimit-store jar 0.0.2
com.google.guava : guava jar 18.0
org.slf4j : slf4j-api jar 1.7.25

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.slf4j : slf4j-simple jar 1.7.25

Project Modules

There are no modules declared in this project.

dimit

分布式流控系统

快速开始

    <dependencies>
        <dependency>
            <groupId>io.github.dzh</groupId>
            <artifactId>dimit-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.dzh</groupId>
            <artifactId>dimit-zk</artifactId>
        </dependency>
    </dependencies>
  • 初始化StoreSystem
String uri = "dimit-zk://dzh/dimit?host=127.0.0.1:2181&sleep=1000&retry=3";
DimitStoreSystem dss = DimitStores.newStoreSystem(URI.create(uri), null);
  • 依次创建流控Conf,配置结构层次:
- DimitConf             定义一个流控器
    - ChannelGroupConf  通道组配置
        - ChannelConf   通道配置

注: 参考单位测试 dimit-demo/../TestZkStoreConfDemo

  • 初始化Dimiter,依据流控Conf创建对应的运行时数据
// init dimiter and runtime channels
String uri = "dimit-zk://dzh/dimit?host=127.0.0.1:2181&sleep=1000&retry=3";
Dimiter dimiter = Dimiter.newDimiter(URI.create(uri), null, dimitConfId);
ChannelGroupWrapper group = demo.initChannelGroup(channelGroupConfId);
group.newChannel(ChannelConfId_1, ChannelType.SEND);
group.newChannel(ChannelConfId_2, ChannelType.SEND);

// select
List<ChannelWrapper> selected = group.select(TagA,TagB);
V result = null;
for(ChannelWrapper channel : selected) {
    try{
        result = channel.call(new ChannelCallable<V>{
            // TODO request
            ...
        });
        // TODO parse result
        ... 
        break;
    }catch(RateLimiterException e){
        LOG.info(e.getMessage(), e);
    }catch(InvalidChannelException e){
        LOG.error(e.getMessage(), e);
    }catch(Exception e){  // or break
        LOG.error(e.getMessage(), e);
    }
}

// program exit
dimiter.close();

注: 参考单位测试 dimit-demo/../TestDimiterDemo

特性列表

  • 流量控制
    • ChannelConf定义max-tps, Channel实例的tps = max-tps / Channel总数
  • Tag筛选
    • ChannelConf定义通道的tag列表,ChannelGroupWrapper.select(...)时选择满足条件的Channel组
  • 主备切换
    • ChannelConf定义通道ChannelStatus, select返回的可用通道列表里PRIMARY优先于STANDBY
  • 质量分析
    • 启用Channel的质量分析功能(stat.enable=true 默认开启),在ChannelWrapper.call()时采集stat信息
  • 异常切换
    • 通过stat信息动态计算ChannelWrapper.priority(), 影响select结果
  • Web管理
    • TODO

环境依赖

  • JDK1.7 or higher
  • maven 3
  • protobuf 3
  • servlet-api v3.1.0 TODO 使用wep4j

文档链接

Versions

Version
0.0.2
0.0.1