项目集成sharding-jdbc

news2024/9/23 4:24:04

目录

项目集成sharding-jdbc

1.业务分析

 2.数据库构建

3.分库分表策略

 项目配置默认数据源

一:导入sharding-jdbc依赖

 二:在application文件中编写配置

三:注释掉主配置文件中配置的数据源

注意:这里添加了spring.main.allow-bean-definition-overriding: true

四:测试

项目配置广播表(公共表)

一:application配置

二:测试

项目使用standard标准模式配置分库算法

一.分库算法类

 二.application中配置逻辑表对应的数据节点和分库算法

项目使用stardard标准模式配置分表算法

一.分表算法类

二.application配置

分库分表注意事项


项目集成sharding-jdbc

1.业务分析

我1们分析一下股票数据的预期增长情况:

表名时间周期累计数量分库分表策略
股票流水表-stock_rt_info1(钟)x60(时)x4(天)x21(月)x1500(重点股票)约等于:750W+按年分库,按月分表
股票主营业务表-stock_business3000+公共表|广播表数据量少
数据变化频率低
各个数据库都会用到
国内大盘流水表-stock_market_index_info1x60x4x21x12x10约等于:60W+按年分库不分表方便数据按年维护
外盘流水表-stock_outer_market_index_info1x60x4x21x12x10约等于:60W+按年分库不分表方便数据按年维护
股票板块-stock_block_rt_into1x60x4x21x12x60约等于:360w+按年分库不分表方便数据按年维护
系统表 -sys_log、sys_user、sys_role等数据量少单库默认数据源

当前我们选择使用cur_time日期字段作为分库分表的片键比较合适,那如果使用主键字段作为分片,会存在哪些问题呢?

  • 数据库扩容时各节点存储均衡问题
    • 股票数据的持续流入会导致前期分库的各个节点不堪重负,最终势必要进行节点扩容,而新加入的节点和旧的节点之间数据不平衡,需要重新规划,这会导致数据迁移的成本过高;
  • 股票查询条件问题
    • 股票数据多以日期作为条件查询,如果基于主键ID作为分片键,则会导致分库的全节点查询,性能开销加大;

 2.数据库构建

  • 对于股票流水表按照月维度和年维护进行库表拆分,也就是说一年会产生一个库用于后期数据归档,而每个库下则按照月份产生12张表,对应一年的数据;
  • 对于板块表和大盘数据表,我们则以年为单位,与股票流水表年份一致即可,也就是按照年分库分表;
  • 对于主营业务表,因为数据量较少,且查询都会用到,作为公共表处理;
  • 对于系统表数据量相对较少,作为默认数据源即可;

 

3.分库分表策略

经过分析发现大盘、板块、股票相关数据的分库策略是一致的,而分表策略则存在部分差异,所以我们可先定义公共的分库算法类和公共的分表算法类,对于不一致的,则个别定义即可:

公共分库算法公共分表算法说明
stock_block_rt_inf
stock_market_index_info
stock_outer_market_index_info
stock_rt_info根据月份分表
stock_business公共表|广播表
系统管理相关表:sys_user等默认数据源

 项目配置默认数据源

说明:配置默认数据源之后,如果某个逻辑表没有对应的数据节点,就会去默认数据源下去寻找是否与自己同名的物理表,如果有就去操作默认数据源的那张表,如果没有就会报错(空数据源即没有可操作的数据源)

一:导入sharding-jdbc依赖

 <!--引入shardingjdbc依赖-->
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
        </dependency>

 二:在application文件中编写配置

application-shard.properties

# 分表配置
# 数据源名称,多数据源以逗号分隔,一个数据库对应一个数据源
spring.shardingsphere.datasource.names=defdb
#让数据源连接指定的数据库
# 数据库连接池类名称
spring.shardingsphere.datasource.defdb.type=com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
spring.shardingsphere.datasource.defdb.driver-class-name=com.mysql.jdbc.Driver
# 数据库 url 连接
spring.shardingsphere.datasource.defdb.url=jdbc:mysql://192.168.200.130:3306/stock_sys_db?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
# 数据库用户名
spring.shardingsphere.datasource.defdb.username=root
# 数据库密码
spring.shardingsphere.datasource.defdb.password=1234

# 配置默认数据源(特点:对于不做分片处理的操作,都会直接访问默认数据源
# 未配置分片规则的表将通过默认数据源定位
spring.shardingsphere.sharding.default-data-source-name=defdb

#开启sql显示到终端
spring.shardingsphere.props.sql.show=true

三:注释掉主配置文件中配置的数据源

# web定义
server:
  port: 8091
spring:
  profiles:
    active: cache,stock,mq,shard #激活其他配置文件
  main:
    allow-bean-definition-overriding: true # 配置允许容器内的bean资源被覆盖,druid的依赖会自动装配数据源,sharding也会装配数据源,
    # 所以要开启覆盖bean资源,让sharding配置的数据源覆盖掉druid的数据源
    # 配置mysql数据源
#  datasource:
#    druid:
#      username: root
#      password: 1234
#      url: jdbc:mysql://192.168.200.130:3306/stock_db?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
#      driver-class-name: com.mysql.jdbc.Driver
#      # 初始化时建立物理连接的个数。初始化发生在显示调用 init 方法,或者第一次 getConnection 时
#      initialSize: 6
#      # 最小连接池数量
#      minIdle: 2
#      # 最大连接池数量
#      maxActive: 20
#      # 获取连接时最大等待时间,单位毫秒。配置了 maxWait 之后,缺省启用公平锁,
#      # 并发效率会有所下降,如果需要可以通过配置 useUnfairLock 属性为 true 使用非公平锁。
#      maxWait: 60000
# 配置mybatis
mybatis:
  type-aliases-package: com.hhh.stock.pojo.entity  #批量给实体类取别名,方便在xml文件中使用别名
  mapper-locations: classpath:mapper/*.xml  #配置加载mapperXml文件资源
  configuration:
    map-underscore-to-camel-case: true # 开启驼峰映射
#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #通过mybatis执行的sql以日志文件输出到终端
    cache-enabled: false #禁止二级缓存 caffiencache
    local-cache-scope: statement # 以及缓存默认开启session
# pagehelper配置
pagehelper:
  helper-dialect: mysql #指定分页数据库类型(方言)
  reasonable: true #合理查询超过最大页,则查询最后一页

注意:这里添加了spring.main.allow-bean-definition-overriding: true

如果不添加这个语句,启动项目时就会报错,因为下面两个依赖都会自动装配一个druid数据源,导致springboot不知道要使用哪一个数据源,所以添加spring.main.allow-bean-definition-overriding: true,配置允许容器内的bean资源被覆盖即可,这样就可以去使用sharding-jdbc的数据源了

 <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
        </dependency>
 <!--引入shardingjdbc依赖-->
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
        </dependency>

四:测试

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * @Description 测试默认数据源的配置
     */
    @Test
    public void testDefault(){
        SysUser user = sysUserMapper.selectByPrimaryKey(1237361915165020161l);
        System.out.println(user);
    }

可以发现使用了默认数据源defdb

5,23 

项目配置广播表(公共表)

前提:每个 库中都要有这张广播表,这样在java程序中对逻辑表操作时,就会操作每个库的这张广播表

一:application配置

# 分表配置
# 数据源名称,多数据源以逗号分隔,一个数据库对应一个数据源
spring.shardingsphere.datasource.names=defdb,ds-2022,ds-2023,ds-2024
#让数据源连接指定的数据库
# 数据库连接池类名称
spring.shardingsphere.datasource.defdb.type=com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
spring.shardingsphere.datasource.defdb.driver-class-name=com.mysql.jdbc.Driver
# 数据库 url 连接
spring.shardingsphere.datasource.defdb.url=jdbc:mysql://192.168.200.130:3306/stock_sys_db?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
# 数据库用户名
spring.shardingsphere.datasource.defdb.username=root
# 数据库密码
spring.shardingsphere.datasource.defdb.password=1234

#让数据源连接指定的数据库
# 数据库连接池类名称
spring.shardingsphere.datasource.ds-2022.type=com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
spring.shardingsphere.datasource.ds-2022.driver-class-name=com.mysql.jdbc.Driver
# 数据库 url 连接
spring.shardingsphere.datasource.ds-2022.url=jdbc:mysql://192.168.200.130:3306/stock_db_2022?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
# 数据库用户名
spring.shardingsphere.datasource.ds-2022.username=root
# 数据库密码
spring.shardingsphere.datasource.ds-2022.password=1234
#让数据源连接指定的数据库
# 数据库连接池类名称
spring.shardingsphere.datasource.ds-2023.type=com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
spring.shardingsphere.datasource.ds-2023.driver-class-name=com.mysql.jdbc.Driver
# 数据库 url 连接
spring.shardingsphere.datasource.ds-2023.url=jdbc:mysql://192.168.200.130:3306/stock_db_2023?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
# 数据库用户名
spring.shardingsphere.datasource.ds-2023.username=root
# 数据库密码
spring.shardingsphere.datasource.ds-2023.password=1234

#让数据源连接指定的数据库
# 数据库连接池类名称
spring.shardingsphere.datasource.ds-2024.type=com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
spring.shardingsphere.datasource.ds-2024.driver-class-name=com.mysql.jdbc.Driver
# 数据库 url 连接
spring.shardingsphere.datasource.ds-2024.url=jdbc:mysql://192.168.200.130:3306/stock_db_2024?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
# 数据库用户名
spring.shardingsphere.datasource.ds-2024.username=root
# 数据库密码
spring.shardingsphere.datasource.ds-2024.password=1234


# 指定stock_business为公共表,多个公共表以逗号间隔
spring.shardingsphere.sharding.broadcast‐tables=stock_business

# 配置默认数据源(特点:对于不做分片处理的操作,都会直接访问默认数据源
# 未配置分片规则的表将通过默认数据源定位
spring.shardingsphere.sharding.default-data-source-name=defdb

#开启sql显示到终端
spring.shardingsphere.props.sql.show=true

二:测试

    /**
     * @Description 测试广播表
     */
    @Test
    public void testBroadCast(){
        StockBusiness pojo = StockBusiness.builder().stockCode("90000")
                .stockName("900000")
                .blockLabel("900000")
                .blockName("900000")
                .business("900000")
                .updateTime(new Date())
                .build();
        stockBusinessMapper.insert(pojo);

        //stockBusinessMapper.deleteByPrimaryKey("90000");
    }

可以发现对四个数据源的sys_business广播表都进行了操作 

项目使用standard标准模式配置分库算法

一.分库算法类

/**
 * 定义公共的分库算法类:个股,大盘,板块都需要此分库算法
 * 泛型是分片键的类型,分片键是cur_time为datetime类型,java中为Date类型
 */
public class CommonAlg4Db implements PreciseShardingAlgorithm<Date>, RangeShardingAlgorithm<Date> {
    /**
     * 精准查询的分库算法(条件为 = in)
     * select * from stock_block_rt_info where cur_time=xxx
     * @param dsNames 根据逻辑表对应的数据节点获取数据源
     *                ds-2022,ds-2023,ds-2024
     * @param preciseShardingValue 逻辑表名称,分片键名称,条件值
     */

    @Override
    public String doSharding(Collection<String> dsNames, PreciseShardingValue<Date> preciseShardingValue) {
        //获取逻辑表名称
        String logicTableName = preciseShardingValue.getLogicTableName();
        //获取分片键名称
        String columnName = preciseShardingValue.getColumnName();
        //获取条件值
        Date curTime = preciseShardingValue.getValue();
        //获取条件值的年,并转换成String类型
        String year=new DateTime(curTime).getYear()+"";
        //编写分库算法,来决定要返回的数据源
        Optional<String> result = dsNames.stream().filter(dsName -> dsName.endsWith(year)).findFirst();
        //返回数据源,如果没有匹配的数据源,就返回默认值null
        return result.orElse(null);
    }

    /**
     * 范围查询的算法,条件为(between and)
     * select * from stock_block_rt_info where cur_time between xxx and xxx;
     * @param dsNames 根据逻辑表对应的数据节点获取数据源
     *                ds-2022,ds-2023,ds-2024
     * @param rangeShardingValue 逻辑表名称,分片键名称,条件值
     */

    @Override
    public Collection<String> doSharding(Collection<String> dsNames, RangeShardingValue<Date> rangeShardingValue) {
       //获取逻辑表的名称
        String logicTableName = rangeShardingValue.getLogicTableName();
        //获取分片键的名称
        String columnName = rangeShardingValue.getColumnName();
        //获取条件值的范围
        Range<Date> valueRange = rangeShardingValue.getValueRange();
        //判断是否有下限
        if(valueRange.hasLowerBound()){
            //获取下限的年份
            int startYear = new DateTime(valueRange.lowerEndpoint()).getYear();
            //ds-2022,ds-2023,ds-2024
            //编写分库算法,找出年份>=startYear的数据源,以-为分割符,取出年份并转换成int类型,然后过滤出>=startYear的数据源,并收集起来
            dsNames=dsNames.stream().filter(dsName->Integer.parseInt(dsName.split("-")[1])>=startYear).collect(Collectors.toList());
        }
        //判断是否有上限
        if(valueRange.hasUpperBound()){
            //获取上限的年份
            int endYear = new DateTime(valueRange.upperEndpoint()).getYear();
            //ds-2022,ds-2023,ds-2024
            //编写分库算法,找出年份<=endYear的数据源,以-为分割符,取出年份并转换成int类型,然后过滤出<=endYear的数据源,并收集起来
            dsNames=dsNames.stream().filter(dsName->Integer.parseInt(dsName.split("-")[1])<=endYear).collect(Collectors.toList());
        }
        //返回数据源
        return dsNames;
    }
}

 二.application中配置逻辑表对应的数据节点和分库算法

# 逻辑表对应的配置数据节点
# 由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持 inline 表达式
spring.shardingsphere.sharding.tables.stock_outer_market_index_info.actual-data-nodes=ds-${2022..2024}.stock_outer_market_index_info
spring.shardingsphere.sharding.tables.stock_market_index_info.actual-data-nodes=ds-${2022..2024}.stock_market_index_info
spring.shardingsphere.sharding.tables.stock_block_rt_info.actual-data-nodes=ds-${2022..2024}.stock_block_rt_info
spring.shardingsphere.sharding.tables.stock_rt_info.actual-data-nodes=ds-2022.stock_rt_info_${202201..202212},ds-2023.stock_rt_info_${202301..202312},ds-2024.stock_rt_info_${202401..202412}




#使用标准标准方式分表
common.algorithm.db=com.hhh.stock.sharding.CommonAlg4Db

# stock_rt_info使用cur_time作为分库的分片键
spring.shardingsphere.sharding.tables.stock_rt_info.database-strategy.standard.sharding-column=cur_time
# 精确分片算法类名称,用于 = 和 IN。该类需实现 PreciseShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_rt_info.database-strategy.standard.precise-algorithm-class-name=${common.algorithm.db}
# 范围分片算法类名称,用于 BETWEEN,可选。该类需实现 RangeShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_rt_info.database-strategy.standard.range-algorithm-class-name=${common.algorithm.db}

# stock_outer_market_index_info使用cur_time作为分库的分片键
spring.shardingsphere.sharding.tables.stock_outer_market_index_info.database-strategy.standard.sharding-column=cur_time
# 精确分片算法类名称,用于 = 和 IN。该类需实现 PreciseShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_outer_market_index_info.database-strategy.standard.precise-algorithm-class-name=${common.algorithm.db}
# 范围分片算法类名称,用于 BETWEEN,可选。该类需实现 RangeShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_outer_market_index_info.database-strategy.standard.range-algorithm-class-name=${common.algorithm.db}

# stock_market_index_info使用cur_time作为分库的分片键
spring.shardingsphere.sharding.tables.stock_market_index_info.database-strategy.standard.sharding-column=cur_time
# 精确分片算法类名称,用于 = 和 IN。该类需实现 PreciseShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_market_index_info.database-strategy.standard.precise-algorithm-class-name=${common.algorithm.db}
# 范围分片算法类名称,用于 BETWEEN,可选。该类需实现 RangeShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_market_index_info.database-strategy.standard.range-algorithm-class-name=${common.algorithm.db}

# stock_block_rt_info使用cur_time作为分库的分片键
spring.shardingsphere.sharding.tables.stock_block_rt_info.database-strategy.standard.sharding-column=cur_time
# 精确分片算法类名称,用于 = 和 IN。该类需实现 PreciseShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_block_rt_info.database-strategy.standard.precise-algorithm-class-name=${common.algorithm.db}
# 范围分片算法类名称,用于 BETWEEN,可选。该类需实现 RangeShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_block_rt_info.database-strategy.standard.range-algorithm-class-name=${common.algorithm.db}

项目使用stardard标准模式配置分表算法

一.分表算法类

/**
 * 个股流水表的分表算法,使用cur_time分片,泛型是Date类型
 */
public class CommonAlg4Tb implements PreciseShardingAlgorithm<Date>, RangeShardingAlgorithm<Date> {
    /**
     * 精准查询的分库算法(条件为 = in)
     * select * from stock_rt_info where cur_time=xxx
     * @param tbNames 根据逻辑表对应的数据节点获取物理表
     *                stock_rt_info_202201,stock_rt_info_202212
     * @param preciseShardingValue 逻辑表名称,分片键名称,条件值
     */
    @Override
    public String doSharding(Collection<String> tbNames, PreciseShardingValue<Date> preciseShardingValue) {
        //获取逻辑表
        String logicTableName = preciseShardingValue.getLogicTableName();
        //获取分片键名称
        String columnName = preciseShardingValue.getColumnName();
        //获取条件值
        Date curDate = preciseShardingValue.getValue();
        //获取年月
        String yearMonth = new DateTime(curDate).toString(DateTimeFormat.forPattern("yyyyMM"));
        //编写分表算法来找出特定时间的物理表
        Optional<String> result = tbNames.stream().filter(tbName -> tbName.endsWith(yearMonth)).findFirst();
        return result.orElse(null);
    }

    /**
     * 范围查询的算法,条件为(between and)
     * select * from stock_block_rt_info where cur_time between xxx and xxx;
     * @param tbNames 根据逻辑表对应的数据节点获取物理表
     *                stock_rt_info_202201,stock_rt_info_202212
     * @param rangeShardingValue 逻辑表名称,分片键名称,条件值
     */
    @Override
    public Collection<String> doSharding(Collection<String> tbNames, RangeShardingValue<Date> rangeShardingValue) {
       //获取条件值
        Range<Date> valueRange = rangeShardingValue.getValueRange();
        if(valueRange.hasLowerBound()){
            int startYearMonth=Integer.parseInt(new DateTime(valueRange.lowerEndpoint()).toString(DateTimeFormat.forPattern("yyyyMM")));
            //编写分表算法来找出特定时间的物理表
            //stock_rt_info_202201,通过最后一个_来再加1获取起始索引,来截取yearMonth
            tbNames=tbNames.stream().filter(tbName->Integer.parseInt(tbName.substring(tbName.lastIndexOf("_")+1))>=startYearMonth).collect(Collectors.toList());
        }
        if(valueRange.hasUpperBound()){
            int endYearMonth=Integer.parseInt(new DateTime(valueRange.upperEndpoint()).toString(DateTimeFormat.forPattern("yyyyMM")));
            //编写分表算法来找出特定时间的物理表
            //stock_rt_info_202201,通过最后一个_来再加1获取起始索引,来截取yearMonth
            tbNames=tbNames.stream().filter(tbName->Integer.parseInt(tbName.substring(tbName.lastIndexOf("_")+1))<=endYearMonth).collect(Collectors.toList());
        }
        return tbNames;
    }
}

二.application配置

#使用标准方式分表
common.algorithm.tb=com.hhh.stock.sharding.CommonAlg4Tb
# stock_rt_info使用cur_time作为分表的分片键
spring.shardingsphere.sharding.tables.stock_rt_info.table-strategy.standard.sharding-column=cur_time
# 精确分片算法类名称,用于 = 和 IN。该类需实现 PreciseShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_rt_info.table-strategy.standard.precise-algorithm-class-name=${common.algorithm.tb}
# 范围分片算法类名称,用于 BETWEEN,可选。该类需实现 RangeShardingAlgorithm 接口并提供无参数的构造器
spring.shardingsphere.sharding.tables.stock_rt_info.table-strategy.standard.range-algorithm-class-name=${common.algorithm.tb}

分库分表注意事项

基于sharding-jdbc实践分库分表注意事项:

  • 条件查询时分片字段不要使用函数处理,否则分片算法失效,导致全节点查询

    • 举例:select * from stock_rt_info where date_format(cur_time,‘%Y%m%d’)='20220910' ,函数会造成sharding的分片失效,导致全节点查询;
    • 同时在索引角度看,如果查询的分片字段使用函数,会导致索引失效,导致查询性能较低;
  • 条件查询时尽量使用符合sharding分片条件的关键字

    • 精准查询尽量使用in =,而范围查询尽量使用between ;
    • between和(in =)不要一起使用
  • sharding-jdbc对嵌套查询处理不友好

    • 如果嵌套查询的话,那么最好子查询的条件只命中单张表。如果子查询的条件关联了多张表,那么交易分步骤拆分实现;
    • 示例:我们项目中的K线统计中,需要将SQL拆分,然后分步骤实现;

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2156519.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于51单片机的矿井安全检测系统

基于51单片机的矿井安全检测系统使用51单片机作为系统主控&#xff0c;LCD1602进行显示同时系统集成了ADC0808和烟雾传感器、甲烷传感器&#xff0c;二者结合测量环境烟雾值&#xff0c;同时使用DHT11温湿度传感器获取环境温湿度值&#xff0c;使用L298N驱动风扇&#xff0c;利…

2009考研数学真题解析-数二:

第一题&#xff1a; 解析&#xff1a;先找间断点&#xff1a;分母不能等于0&#xff0c;分母是sinΠx&#xff0c; 因此不难看出间断点是x0&#xff0c;-1&#xff0c;-2&#xff0c;-3。。。。。 接着一个一个来算这些点是什么间断点。 &#xff0c;从x趋于2开始&#xff0c;分…

2024年一区极光优化+分解+深度学习!VMD-PLO-Transformer-GRU多变量时间序列光伏功率预测

2024年一区极光优化分解深度学习&#xff01;VMD-PLO-Transformer-GRU多变量时间序列光伏功率预测 目录 2024年一区极光优化分解深度学习&#xff01;VMD-PLO-Transformer-GRU多变量时间序列光伏功率预测效果一览基本介绍程序设计参考资料 效果一览 基本介绍 1.中秋献礼&#…

FiBiNET模型实现推荐算法

1. 项目简介 A031-FiBiNET模型项目是一个基于深度学习的推荐系统算法实现&#xff0c;旨在提升推荐系统的性能和精度。该项目的背景源于当今互联网平台中&#xff0c;推荐算法在电商、社交、内容分发等领域的广泛应用。推荐系统通过分析用户的历史行为和兴趣偏好&#xff0c;预…

小球轻重的测量

设有12个小球。其中11个小球的重量相同&#xff0c;称为好球&#xff1b;有一个小球的重量与11个好球的重量不同&#xff08;或轻或重&#xff09;&#xff0c;称这个小球为坏球。试编写一个算法&#xff0c;用一个无砝码的天平称三次找出这个坏球&#xff0c;并确定其比好球轻…

GAMES101(15节,辐射,BRDF)

Irradiance辐射度量学 辐射度量学在渲染领域&#xff0c;可以帮助理解基于物理的光照模型 radiant energy辐射能量Q&#xff0c;累计总能量&#xff08;单位J joule焦耳&#xff09;&#xff0c;就像太阳能板&#xff0c;光照时间越长接收能量越多&#xff0c;收到的能量总和…

02_RabbitMQ消息丢失解决方案及死信队列

一、数据丢失 第一种&#xff1a;生产者弄丢了数据。生产者将数据发送到 RabbitMQ 的时候&#xff0c;可能数据就在半路给搞丢了&#xff0c;因为网络问题&#xff0c;都有可能。 第二种&#xff1a;RabbitMQ 弄丢了数据。MQ还没有持久化自己挂了。 第三种&#xff1a;消费端…

Attention is All You Need精读

原文开头&#xff0c;不是搬运 dog。All attention is all you need Abstract 摘要 这篇文章的内容源于基于编码器-解码器架构的RNN模型&#xff0c;在其他人的工作中&#xff0c;我们可以发现注意力机制对于提升编码器-解码器架构模型的性能很重要。这篇文章提出了一个比较简…

《代码整洁之道:程序员的职业素养》

作者&#xff1a;【美】Robert C. Martin 第1章 专业主义 专业主义就意味着担当责任&#xff0c;软件开发太复杂了&#xff0c;不可能没什么 bug。但很不幸&#xff0c;这并不能为你开脱。人体太复杂了&#xff0c;不可能尽知其全部&#xff0c;但医生仍要发誓不伤害病人。如…

隐藏excel单元格数据的两个方法

在Excel中&#xff0c;公式是用来计算数据和结果的非常重要的一部分。但是&#xff0c;有时候您可能希望隐藏公式&#xff0c;以保护其不被他人修改或查看。那么今天小编就来给大家分享隐藏excel单元格数据的方法。 一、使用“隐藏”功能 在Excel中&#xff0c;我们还可以使用…

ZYNQ学习--AXI总线协议

一、AXI 总线简介 AXI&#xff08;Advanced Extensible Interface&#xff09;高级拓展总线是AMBA&#xff08;Advanced Microcontroller Bus Architecture&#xff09;高级微控制总线架构中的一个高性能总线协议&#xff0c;由ARM公司开发。AXI总线协议被广泛应用于高带宽、低…

大语言模型超参数调优:开启 AI 潜能的钥匙

前言 在人工智能的广袤领域中&#xff0c;大语言模型&#xff08;LLM&#xff09;凭借其强大的实力&#xff0c;不断重塑着我们对机器理解语言的认知。然而&#xff0c;要使这些模型在特定应用场景中发挥最大效能&#xff0c;关键在于巧妙调整其超参数。本文将引领你深入探究 …

x-cmd pkg | bat: cat 命令现代化替代品,终端用户必备工具

目录 简介快速上手安装使用与第三方工具组合使用 功能特点竞品和相关作品进一步阅读 简介 bat 是由 github.com/sharkdp 用 Rust 开发的 cat 命令现代化替代品。它比 cat 命令扩展了更多的现代化功能&#xff0c;如语法高亮、自动分页、Git集成等&#xff0c;能为用户提供更为…

python如何跨文件调用自己定义的函数

当自己定义函数过多时&#xff0c;只有一个python文件时代码会很长&#xff0c;不易理清代码框架&#xff0c;比如下面这段代码&#xff0c;如何隐藏具体函数细节呢&#xff1f;也就是把def函数放到另外一个python文件里步骤如下&#xff1a; 一个python文件代码篇幅过长 imp…

结构体对齐、函数传参、库移植

结构体字节对齐 按固定位大小匹配地址&#xff0c;a:10b:1020位 <32位4字节 202040位>32位 所以ab20作为一个int型&#xff0c;int c:20 单独做4个字节&#xff08;int&#xff09; 101020 &#xff08;int&#xff09;4个字节 &#xff0c;20&#xff08;int&#x…

算法之逻辑斯蒂回归(Logistic regression)

简介&#xff1a;个人学习分享&#xff0c;如有错误&#xff0c;欢迎批评指正。 逻辑斯蒂回归&#xff08;Logistic Regression&#xff09;是统计学中一种广泛应用于二分类问题的算法。它的主要目标是预测二分类问题中的事件发生的概率。尽管名字里有“回归”&#xff0c;但逻…

wordpress迁移到别的服务器

wordpress论坛网站搭建 于2023/11/16写的该文章 一-配置环境 配置LNMP&#xff08;linuxnginxmysqlphpphpmyadmin&#xff09;环境或者LAMP&#xff08;apache&#xff09; 可以选择集成了这些软件的套件 下载链接&#xff1a;https://www.xp.cn/download.html 手动下载这…

https加密原理

以为http的数据都是以明文传送&#xff0c;会有很大的安全问题&#xff0c;所以出现的https协议。https就是在http协议的基础上增加了一个安全层&#xff0c;可以对数据进行加密和解密(例如SSL、TLS等)。 https加密解密的原理&#xff1a;证书非对称加密对称加密 在讲解原理前…

Python爬虫之urllib模块详解

Python爬虫入门 此专栏为Python爬虫入门到进阶学习。 话不多说&#xff0c;直接开始吧。 urllib模块 Python中自带的一个基于爬虫的模块&#xff0c;其实这个模块都几乎没什么人用了&#xff0c;我就随便写写了。 - 作用&#xff1a;可以使用代码模拟浏览器发起请求。&…

2024 年最新前端ES-Module模块化、webpack打包工具详细教程(更新中)

模块化概述 什么是模块&#xff1f;模块是一个封装了特定功能的代码块&#xff0c;可以独立开发、测试和维护。模块通过导出&#xff08;export&#xff09;和导入&#xff08;import&#xff09;与其他模块通信&#xff0c;保持内部细节的封装。 前端 JavaScript 模块化是指…