配置管理的配置与拉取、热更新的配置、动态路由

Superpowers:可编程AI协作协议与Skill工程化实践 AI编程正从提示词驱动迈向工程化协作新范式。Superpowers并非传统代码补全工具,而是一套定义清晰、可版本控制、可调试复用的AI协作协议——它将AI能力抽象为带输入校验、执行管道、输出契约和元数据声明的Skill(类DSL构件),再通过状态驱动的Workflow编排实现跨平台、可熔断、含人工Checkpoint的自动化流水线。其核心价值在于解决AI生成代码长期存在的不可复现、不可审计、不可交接三大痛点,支撑OpenAPI转TS、Figma转Vue等高复用场景落地。本文深入解析Skill设计四重契约与P 阅读详情

目录

配置管理

配置共享:

拉取共享配置:

配置热更新:

动态路由:


配置管理

到目前为止我们已经解决了微服务相关的几个问题:

  • 微服务远程调用

  • 微服务注册、发现

  • 微服务请求路由、负载均衡

  • 微服务登录用户信息传递

不过,现在依然还有几个问题需要解决:

  • 网关路由在配置文件中写死了,如果变更必须重启微服务

  • 某些业务配置在配置文件中写死了,每次修改都要重启服务

  • 每个微服务都有很多重复的配置,维护成本高

这些问题都可以通过统一的配置管理器服务解决。而Nacos不仅仅具备注册中心功能,也具备配置管理的功能:

微服务共享的配置可以统一交给Nacos保存和管理,在Nacos控制台修改配置后,Nacos会将配置变更推送给相关的微服务,并且无需重启即可生效,实现配置热更新。

网关的路由同样是配置,因此同样可以基于这个功能实现动态路由功能,无需重启网关即可修改路由配置。

配置共享:

我们可以把微服务共享的配置抽取到Nacos中统一管理,这样就不需要每个微服务都重复配置了。分为两步:

  • 在Nacos中添加共享配置

  • 微服务拉取配置

我们在nacos控制台分别添加这些配置。

首先是jdbc相关配置,在配置管理->配置列表中点击+新建一个配置:

注意这里的jdbc的相关参数并没有写死,例如:

  • 数据库ip:通过${hm.db.host:192.168.150.101}配置了默认值为192.168.150.101,同时允许通过${hm.db.host}来覆盖默认值

  • 数据库端口:通过${hm.db.port:3306}配置了默认值为3306,同时允许通过${hm.db.port}来覆盖默认值

  • 数据库database:可以通过${hm.db.database}来设定,无默认值

然后是统一的日志配置,命名为shared-log.yaml,配置内容如下:
logging:
  level:
    com.hmall: debug
  pattern:
    dateformat: HH:mm:ss:SSS
  file:
    path: "logs/${spring.application.name}"

然后是统一的swagger配置,命名为shared-swagger.yaml,配置内容如下:

knife4j:
  enable: true
  openapi:
    title: ${hm.swagger.title:黑马商城接口文档}
    description: ${hm.swagger.description:黑马商城接口文档}
    email: ${hm.swagger.email:zhanghuyi@itcast.cn}
    concat: ${hm.swagger.concat:虎哥}
    url: https://www.itcast.cn
    version: v1.0.0
    group:
      default:
        group-name: default
        api-rule: package
        api-rule-resources:
          - ${hm.swagger.package}

注意,这里的swagger相关配置我们没有写死,例如:

  • title:接口文档标题,我们用了${hm.swagger.title}来代替,将来可以有用户手动指定

  • email:联系人邮箱,我们用了${hm.swagger.email:zhanghuyi@itcast.cn},默认值是zhanghuyi@itcast.cn,同时允许用户利用${hm.swagger.email}来覆盖。

拉取共享配置:

1)引入依赖:

在cart-service模块引入依赖:

  <!--nacos配置管理-->
  <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
  </dependency>
  <!--读取bootstrap文件-->
  <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-bootstrap</artifactId>
  </dependency>

2)新建bootstrap.yaml

在cart-service中的resources目录新建一个bootstrap.yaml文件:

spring:
  application:
    name: cart-service # 服务名称
  profiles:
    active: dev
  cloud:
    nacos:
      server-addr: 192.168.150.101 # nacos地址
      config:
        file-extension: yaml # 文件后缀名
        shared-configs: # 共享配置
          - dataId: shared-jdbc.yaml # 共享mybatis配置
          - dataId: shared-log.yaml # 共享日志配置
          - dataId: shared-swagger.yaml # 共享日志配置

3)修改application.yaml

由于一些配置挪到了bootstrap.yaml,因此application.yaml需要修改为:

server:
  port: 8082
feign:
  okhttp:
    enabled: true # 开启OKHttp连接池支持
hm:
  swagger:
    title: 购物车服务接口文档
    package: com.hmall.cart.controller
  db:
    database: hm-cart

配置热更新:

有很多的业务相关参数,将来可能会根据实际情况临时调整。例如购物车业务,购物车数量有一个上限,默认是10,对应代码如下:

现在这里购物车是写死的固定值,我们应该将其配置在配置文件中,方便后期修改。

但现在的问题是,即便写在配置文件中,修改了配置还是需要重新打包、重启服务才能生效。能不能不用重启,直接生效呢?

这就要用到Nacos的配置热更新能力了,分为两步:

  • 在Nacos中添加配置

  • 在微服务读取配置

首先,我们在nacos中添加一个配置文件,将购物车的上限数量添加到配置中:

接着,我们在微服务中读取配置,实现配置热更新。

在cart-service中新建一个属性读取类:

package com.hmall.cart.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "hm.cart")
public class CartProperties {
    private Integer maxAmount;
}

接着,在业务中使用该属性加载类:

测试,向购物车中添加多个商品:

我们在nacos控制台,将购物车上限配置为5:

无需重启,再次测试购物车功能:

动态路由:

网关的路由配置全部是在项目启动时由org.springframework.cloud.gateway.route.CompositeRouteDefinitionLocator在项目启动的时候加载,并且一经加载就会缓存到内存中的路由表内(一个Map),不会改变。也不会监听路由变更,所以,我们无法利用上节课学习的配置热更新来实现路由更新。

因此,我们必须监听Nacos的配置变更,然后手动把最新的路由更新到路由表中。这里有两个难点:

  • 如何监听Nacos配置变更?

  • 如何把路由信息更新到路由表?

首先, 我们在网关gateway引入依赖:

<!--统一配置管理-->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--加载bootstrap-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

然后在网关gateway的resources目录创建bootstrap.yaml文件,内容如下:

spring:
  application:
    name: gateway
  cloud:
    nacos:
      server-addr: 192.168.150.101
      config:
        file-extension: yaml
        shared-configs:
          - dataId: shared-log.yaml # 共享日志配置

接着,修改gateway的resources目录下的application.yml,把之前的路由移除,最终内容如下:

server:
  port: 8080 # 端口
hm:
  jwt:
    location: classpath:hmall.jks # 秘钥地址
    alias: hmall # 秘钥别名
    password: hmall123 # 秘钥文件密码
    tokenTTL: 30m # 登录有效期
  auth:
    excludePaths: # 无需登录校验的路径
      - /search/**
      - /users/login
      - /items/**

然后,在gateway中定义配置监听器:

package com.hmall.gateway.route;

import cn.hutool.json.JSONUtil;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
import com.hmall.common.utils.CollUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionWriter;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;

@Slf4j
@Component
@RequiredArgsConstructor
public class DynamicRouteLoader {

    private final RouteDefinitionWriter writer;
    private final NacosConfigManager nacosConfigManager;

    // 路由配置文件的id和分组
    private final String dataId = "gateway-routes.json";
    private final String group = "DEFAULT_GROUP";
    // 保存更新过的路由id
    private final Set<String> routeIds = new HashSet<>();

    @PostConstruct
    public void initRouteConfigListener() throws NacosException {
        // 1.注册监听器并首次拉取配置
        String configInfo = nacosConfigManager.getConfigService()
                .getConfigAndSignListener(dataId, group, 5000, new Listener() {
                    @Override
                    public Executor getExecutor() {
                        return null;
                    }

                    @Override
                    public void receiveConfigInfo(String configInfo) {
                        updateConfigInfo(configInfo);
                    }
                });
        // 2.首次启动时,更新一次配置
        updateConfigInfo(configInfo);
    }

    private void updateConfigInfo(String configInfo) {
        log.debug("监听到路由配置变更,{}", configInfo);
        // 1.反序列化
        List<RouteDefinition> routeDefinitions = JSONUtil.toList(configInfo, RouteDefinition.class);
        // 2.更新前先清空旧路由
        // 2.1.清除旧路由
        for (String routeId : routeIds) {
            writer.delete(Mono.just(routeId)).subscribe();
        }
        routeIds.clear();
        // 2.2.判断是否有新的路由要更新
        if (CollUtils.isEmpty(routeDefinitions)) {
            // 无新路由配置,直接结束
            return;
        }
        // 3.更新路由
        routeDefinitions.forEach(routeDefinition -> {
            // 3.1.更新路由
            writer.save(Mono.just(routeDefinition)).subscribe();
            // 3.2.记录路由id,方便将来删除
            routeIds.add(routeDefinition.getId());
        });
    }
}

重启网关,任意访问一个接口,比如 http://localhost:8080/search/list?pageNo=1&pageSize=1:

接下来,我们直接在Nacos控制台添加路由,路由文件名为gateway-routes.json,类型为json:

[
    {
        "id": "item",
        "predicates": [{
            "name": "Path",
            "args": {"_genkey_0":"/items/**", "_genkey_1":"/search/**"}
        }],
        "filters": [],
        "uri": "lb://item-service"
    },
    {
        "id": "cart",
        "predicates": [{
            "name": "Path",
            "args": {"_genkey_0":"/carts/**"}
        }],
        "filters": [],
        "uri": "lb://cart-service"
    },
    {
        "id": "user",
        "predicates": [{
            "name": "Path",
            "args": {"_genkey_0":"/users/**", "_genkey_1":"/addresses/**"}
        }],
        "filters": [],
        "uri": "lb://user-service"
    },
    {
        "id": "trade",
        "predicates": [{
            "name": "Path",
            "args": {"_genkey_0":"/orders/**"}
        }],
        "filters": [],
        "uri": "lb://trade-service"
    },
    {
        "id": "pay",
        "predicates": [{
            "name": "Path",
            "args": {"_genkey_0":"/pay-orders/**"}
        }],
        "filters": [],
        "uri": "lb://pay-service"
    }
]

无需重启网关,稍等几秒钟后,再次访问刚才的地址:

【灰度共生矩阵(GLCM)原理及代码实现】 文章主旨详细介绍灰度共生矩阵(Gray-Level Co-occurrence Matrix, GLCM)的生成原理、核心特征量及其在图像纹理分析中的应用,并提供了可运行的Python代码实现。该网页是一篇理论结合实践的优秀技术文章。它不仅清晰地解释了GLCM这一经典纹理分析工具背后的数学原理,还提供了完整、可复现的代码,非常适合计算机视觉或图像处理领域的学习者和开发者入门并实践灰度共生矩阵。读者可以通过运行代码来直观理解GLCM如何工作,并提取图像的纹理特征。 阅读详情

相关推荐

深度解析 CherryECAT:国产 EtherCAT 协议栈与国外主流方案的全方位对比及项目实战(下)

本文深入解析了EtherCAT协议栈技术特性与国产化应用实践。通过对比CherryECAT、TwinCAT、IgHEtherlab等主流协议栈的核心原理、性能指标及适配性,重点展示了国产协议栈CherryECAT在GD32F407+RT-Thread平台上的完整实现案例,包括部分代码示例、实测数据(通信周期100μs±0.8μs,RAM占用13KB)。针对工业机器人、信创项目等不同场景,提供了基于实时性、功能完整性、国产化等维度的量化选型模型。

bother3000的博客 1715

Nacos配置管理

Nacos配置管理功能介绍。

f135917h的博客 1071

万象RK3506-EG1800网关使用说明

摘要:HD-RK3506-EG1800是一款高性能工业物联网边缘计算网关,支持Buildroot和Ubuntu双系统。文档详细介绍了网关的网络配置(包括ETH0/ETH1的静态IP设置、WiFi连接)、时钟同步、HSL软件安装配置(含开机自启动服务)、系统日志优化以及刷机操作指南(Loader/Maskrom模式)。特别提供了基于lighttpd的网页管理方案,通过HTML界面实现网络参数可视化配置,包含身份验证、实时状态显示和表单提交功能。网关默认ETH0固定IP为192.168.1.10,提供完整的CL

tian_jiangnan的博客 186

微服务配置管理

在前面我们已经学习了远程调用,Nacos注册中心,OpenFeign以及网关这些微服务组件。但是我们现在又会面临新的问题,就是微服务、注册中心、网关之中存在许多重复配置,维护成本比较高,另外就是业务配置经常变动,每次修改都要重启服务非常麻烦,网关路由配置写死,如果变更要重启网关。那么现在我们就可以用到配置管理服务。配置管理服务一方面读取配置,另一方面当配置发生改变时,它也可以去推送配置变更。

2301_80339238的博客 1991

关于【中孚计算机终端保密检查系统】的卸载

卸载中孚计算机终端保密检查系统

码农之路,向死而生 4万+

【AI助力科研】不看一篇文献,手把手教你用chatGPT写文献综述!

这篇文章以【AI助力科研】为题,介绍了如何利用ChatGPT编写文献综述的方法。作者通过详细的指导,展示了不需要阅读大量文献,只需依靠ChatGPT模型即可完成文献综述的过程。该方法旨在提高科研工作者的效率,减少阅读负担,并且能够生成具有逻辑性和准确性的文献综述。

研究方向//图像视频处理/信号算法/红外无损检测/数值仿真/机器学习/优化算法/python/matlab 2万+

Nacos配置管理(1)----配置共享

微服务共享的配置可以统一交给Nacos保存和管理,在Nacos控制台修改配置后,Nacos会将配置变更推送给相关的微服务,并且无需重启即可生效,实现配置热更新。我们可以把微服务共享的配置抽取到Nacos中统一管理,这样就不需要每个微服务都重复配置了。网关的路由同样是配置,因此同样可以基于这个功能实现动态路由功能,无需重启网关即可修改路由配置。)初始化时处理的,发生在项目的引导阶段。不过,需要注意的是,读取Nacos配置是SpringCloud上下文(中,那么在项目引导阶段就可以读取nacos中的配置了。

Very_a的博客 2093

全局特征描述子 CVFH (Clustered Viewpoint Feature Histogram) 原理

特性VFHCVFH处理对象整个物体点云物体点云被分割后的稳定表面块(簇)对遮挡的鲁棒性弱。遮挡会破坏全局形状,导致描述子失效。极强。只依赖于稳定存在的部分。描述子维度263 维308 维 (263 + 45 SC)输出数量一个物体产生1 个描述子一个物体可能产生多个签名计算复杂度相对较低较高(需先聚类)主要应用场景完整、分割良好的物体存在遮挡、背景杂波的不完整物体。

weixin_37079656的博客 627

nacos配置管理以及动态路由实现

接下来就是需要把nacos中的配置信息合并到本地的application.yaml文件中,在读取application.yaml配置文件之前是一个bootstrap.yaml文件来读取的,所以我们要创建一个bootstrap.yaml配置文件来知道nacos的地址,再进行合并配置。微服务共享的配置可以统一交给Nacos保存和管理,在Nacos控制台修改配置后,Nacos会将配置变更推送给相关的微服务,并且无需重启即可生效,实现配置热更新。//这样开启服务就可以动态监听到路由, 不需要重启网关服务。

m0_58853158的博客 860

数字IC设计实现之hierarchical flow系列(一)

数字IC设计实现之hierarchical flow系列(一) 最近这段时间小编又比较忙起来了,今天抽空来咖啡厅码字来了,刚到时脑子一片空白,不知道要分享些什么(项目结束后将会在知识星球上分享数字 IC 设计实现 Tapeout 前要review的那些 checklist)。突然间想起来有个星友希望小编分享些数字 IC 设计实现 hierarchical flow 的相关内容。考虑到现在大都采用这种方式来做 design 和实现,那就选这个 topic 了。限于篇幅和时间限制,今天只分享逻辑综合部分和布局布

weixin_37584728的博客 6012

验证码破解2.0:Python+CV大模型搞定滑块/点选验证

核心创新:基于YOLOv8+SAM CV大模型的端到端验证码破解方案,无需人工设计特征,适配多种验证码类型;核心价值高成功率:滑块验证≥95%,点选验证≥90%,远超传统CV方案;低延迟:单验证码破解≤2秒,满足高并发采集需求;行为模拟:生成符合人类操作的轨迹,绕过行为检测;易扩展:统一架构支持新增验证码类型,仅需少量标注数据微调;技术要点采用YOLOv8实现快速目标检测,SAM实现像素级分割;生成物理规律的人类轨迹,模拟真实操作行为;

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1264

Spring Cloud Config使用Nacos进行配置管理

使用addListener之前要先加载一次Nacos的配置信息,后期监听配置变更与获取到的第一次Nacos配置信息进行对比,判断是否发生变化,变化则调用回调函数new Listener(){},new Listener(){}需要实现两个方法getExecutor()、receiveConfigInfo(),其中getExcutor()是返回一个现线程池使回调函数可以交由线程池进行异步执行,receiveConfigInfo()是处理配置变更的函数。Naocs提供了一个直接获取Nacos配置信息的类。

m0_74751974的博客 1164

CMake是什么?为什么学习CMake

CMake的主要作用和重要性,包括其在跨平台构建中的应用、如何支持多种编译器及操作系统,以及它在管理大型和复杂项目中的优势。

小鱼酱的博客 3884

微服务-配置管理

快速了解微服务的热更新内容(路由配置,业务逻辑配置....)

2302_77423520的博客 1274

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

MP+Docker+SpringCloud+MQ+ES——10 配置管理

讲解Nacos的配置管理功能,包括微服务中共用的yaml文件的共享配置、业务相关参数的共享配置(支持热更新)、动态路由配置。

念头通达 895

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Java微服务day04-配置管理(Nacos)

(1)代码中有非常多的数据是固定,比如黑马商城购物车业务,购物车数量有一个上限,默认是10,,现在这里购物车是写死的固定值,我们应该将其配置在配置文件中,方便后期修改。但现在的问题是,即便写在配置文件中,修改了配置还是需要重新打包、重启服务才能生效。能不能不用重启,直接生效呢?这就要用到 Nacos 的配置热更新能力了,分为两步: 1 在 Nacos 中添加配置 2 在微服务读取配置。

ShSLb_的博客 678

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

【SpringCloud】Gateway

路由过滤器,作用范围比较灵活,可以是任意指定的路由Route:全局过滤器,作用范围是所有路由,不可配置。

Etenal_的博客 4808

服务治理---注册中心,配置管理,openfeign

在微服务拆分的理念中,我们必须遵循每个服务尽量的完全独立,类独立,接口独立,方法独立,不依赖别的服务,这样就最大程度的耦合性降低。但随之而来的却是一系列问题,像我们一个接口可能就会调用别的服务的接口,这样就会逻辑上的跨越主机。

卡辣密学习中的博客 2768

SpringCloud配置管理

本文介绍了基于Nacos的配置管理方案,重点解决微服务架构中的三个核心问题:1. 配置共享问题,通过Nacos统一管理数据库连接、日志等公共配置;2. 配置热更新问题,使用@ConfigurationProperties实现配置动态刷新,避免重启服务;3. 网关动态路由问题,通过监听Nacos配置变更实现路由规则实时更新。文中详细说明了Nacos配置中心的集成方式,包括bootstrap.yml配置、共享配置文件管理、热更新实现机制,并提供了网关动态路由的完整代码实现方案,有效解决了传统架构中配置分散、维护

Saness1y的博客 405

微服务学习(二)

资料来源黑马程序员SpringCloud课程笔记,偷个懒直接拿来用了。如果看过的话可以看后面的开发博文。

screamn的博客 1128

网关路由SpringCloudGateway、nacos配置管理(热更新、动态路由)

前端请求不能直接访问微服务,而是要请求网关(SpringCloudGateway)网关干什么?路由过滤,登录校验。nacos既是注册中心也可用作配置管理,用来解决各个微服务块配置文件中相同的配置冗余,配置热更新属性,动态路由等。

qq_51076441的博客 3904

nacos 配置管理、 配置热更新、 动态路由

统一配置管理可以解决多服务配置过的问题,同时该服务配置文件移交配置中心 处理信息 配置 pom.xml 添加 config 和 bootstrap 的 jar 包 添加 bootstrap.yaml 文件配置 配置说明 spring.application.name: 指定微服务的名称(cart-service),Nacos 会根据该名称加载对应的配置。 spring.profiles.active: 指定当前激活的环境(dev),Nacos 会加载 cart-service-dev.yaml 配置。 sp

ling_zhi_xin的博客 1760

微服务-网关、配置热更新、动态路由

网关、网关登录校验、配置管理、配置热更新、动态路由

hello77的blogggg 祝你得偿所愿 1461
上一篇: 网关、路由、过滤、登录校验、用户信息传递
下一篇: 雪崩问题及其解决方案(请求限流、线程隔离、服务熔断、fallback、sentinel实现以上功能)
Le1Yu
博客等级 码龄2年 48粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值