跟我学CSE系列之6:dubbo应用如何接入CSE

RPC方式开发ServiceComb应用程序 RPC方式开发ServiceComb应用程序 步骤: 框架结构:一个父工程,三个子模块(服务接口,服务提供者,服务消费者) 开发服务接口,安装服务接口到本地仓库 开发服务提供者,导入坐标 <!-- rpc通信模型--> <dependency> <groupId>org.apache.servicecomb</group... 阅读详情

Dubbo和Java chassis底层都使用了Spring的依赖注入和bean管理系统,所以使用Dubbo的服务迁移到ServiceComb工作量较小, 主要改动在依赖和配置方面。

服务提供方

替换依赖

将对dubbo的依赖替换为对Java chassis的依赖

Dubbo

  <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>${dubbo.version}</version>
  </dependency>

Java chassis

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.servicecomb</groupId>
        <artifactId>java-chassis-dependencies</artifactId>
        <version>${java.chassis.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  
  <dependencies>
    <dependency>
      <groupId>io.servicecomb</groupId>
      <artifactId>transport-highway</artifactId>
    </dependency>
    <dependency>
      <groupId>io.servicecomb</groupId>
      <artifactId>transport-rest-vertx</artifactId>
    </dependency>
    <dependency>
      <groupId>io.servicecomb</groupId>
      <artifactId>provider-pojo</artifactId>
    </dependency>
  </dependencies>

替换服务接口注释

以 @Service 注释方式暴露的服务接口,用 @RpcSchema 替代

Dubbo

import com.alibaba.dubbo.config.annotation.Service;

@Service
public class SomeServiceImpl implements SomeService {
  // ...
}

Java chassis

@RpcSchema(schemaId = "someServiceEndpoint")
public class SomeServiceImpl implements SomeService {
  // ...
}

修改提供方启动入口

Dubbo

public class ProviderMain
{

  public static void main(String[] args) throws Exception
  {
    @SuppressWarnings(
    { "resource", "unused" })
    ApplicationContext context = new ClassPathXmlApplicationContext("conf/applicationContext.xml");
    System.out.println("Dubbo provider started successfully...");

    System.in.read();
  }
}

Java chassis

public class ProviderMain
{

  public static void main(String[] args) throws Exception
  {
    Log4jUtils.init();
    BeanUtils.init();

    System.out.println("ServiceComb provider started successfully...");
  }
}

修改服务提供方配置

Dubbo服务通过一个XML文件同时配置了服务接口、服务注册中心地址、服务监听端口等所有内容。

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

  <dubbo:application name="provider-service" />

  <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />

  <dubbo:protocol name="dubbo" port="20880" />

  <dubbo:annotation package="io.servicecomb.demo" />

  <!-- 以XML配置方式暴露的服务 -->
  <dubbo:service interface="io.servicecomb.demo.api.AnotherService" ref="anotherServiceImpl" />
  <bean id="anotherServiceImpl" class="io.servicecomb.demo.provider.AnotherServiceImpl" />

</beans>

Java chassis也同样提供了以XML文件暴露服务接口的方式,但其他服务配置则通过 microservice.yaml 文件提供。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:util="http://www.springframework.org/schema/util" xmlns:cse="http://www.huawei.com/schema/paas/cse/rpc"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.huawei.com/schema/paas/cse/rpc classpath:META-INF/spring/spring-paas-cse-rpc.xsd">

  <!-- 以XML配置方式暴露的服务 -->
  <cse:rpc-schema schema-id="anotherServiceEndpoint" implementation="io.servicecomb.demo.provider.AnotherServiceImpl"/>
</beans>
APPLICATION_ID: my-application
service_description:
  name: service-provider
  version: 0.0.1
cse:
  service:
    registry:
      address: http://127.0.0.1:30100 # 服务注册中心地址
  rest:
    address: 0.0.0.0:8080 # 服务REST端口

服务消费方

替换依赖

将对Dubbo的依赖替换为对Java chassis的依赖

Dubbo

  <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>${dubbo.version}</version>
  </dependency>

Java chassis

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.servicecomb</groupId>
        <artifactId>java-chassis-dependencies</artifactId>
        <version>${java.chassis.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  
  <dependencies>
    <dependency>
      <groupId>io.servicecomb</groupId>
      <artifactId>transport-highway</artifactId>
    </dependency>
    <dependency>
      <groupId>io.servicecomb</groupId>
      <artifactId>transport-rest-vertx</artifactId>
    </dependency>
    <dependency>
      <groupId>io.servicecomb</groupId>
      <artifactId>provider-pojo</artifactId>
    </dependency>
  </dependencies>

修改消费方启动入口

Dubbo

public class ConsumerMain
{

  public static void main(String[] args) throws Exception
  {
    @SuppressWarnings(
    { "resource", "unused" })
    ApplicationContext context = new ClassPathXmlApplicationContext("conf/applicationContext.xml");
    System.out.println("Dubbo Consumer started successfully...");

    System.in.read();
  }
}

Java chassis

public class ConsumerMain
{

  public static void main(String[] args) throws Exception
  {
    Log4jUtils.init();
    BeanUtils.init();

    System.out.println("ServiceComb Consumer started successfully...");
  }
}

服务异步调用

Dubbo

  SomeService someService = (SomeService) context.getBean("someServiceRef");
  String hello = someService.sayHello("world");
  Future<String> future = RpcContext.getContext().getFuture();
  return future.get();

Java chassis

  ApplicationContext context = BeanUtils.getContext();
  SomeService someService = (SomeService) context.getBean("someServiceRef");
  
  CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> someService.sayHello("world"));
  return future.get();

修改服务提供方配置

Dubbo服务通过一个XML文件同时配置了远程服务提供方接口、服务注册中心地址、服务监听端口等所有内容。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

  <dubbo:application name="consumer-service" />

  <dubbo:protocol name="dubbo" port="20880"/>
  <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />

  <dubbo:reference id="someServiceRef"
    interface="io.servicecomb.demo.api.SomeService"
    async="true" timeout="30000" />

  <dubbo:reference id="anotherServiceRef"
    interface="io.servicecomb.demo.api.AnotherService"
    async="true" timeout="30000" />
</beans>

Java chassis也同样提供了以XML文件引用远程服务提供方接口的方式,但其他服务配置则通过 microservice.yaml 文件提供。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:util="http://www.springframework.org/schema/util" xmlns:cse="http://www.huawei.com/schema/paas/cse/rpc"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.huawei.com/schema/paas/cse/rpc classpath:META-INF/spring/spring-paas-cse-rpc.xsd">


  <cse:rpc-reference id="someServiceRef" microservice-name="service-provider"
    schema-id="someServiceEndpoint" interface="io.servicecomb.demo.api.SomeService"/>
    
  <cse:rpc-reference id="anotherServiceRef" microservice-name="service-provider"
    schema-id="anotherServiceEndpoint" interface="io.servicecomb.demo.api.AnotherService"/>
</beans>
APPLICATION_ID: my-application
service_description:
  name: service-consumer
  version: 0.0.1
cse:
  service:
    registry:
      address: http://127.0.0.1:30100
华为云CSE关键特性,支持托管Nacos注册配置中心 作为服务注册发现中心,CSE Nacos正常情况下只会给服务消费者返回健康的服务提供者实例,当用户应用访问量激增,所有的调用都只会转发到健康实例,可能导致服务的崩溃,产生雪崩效应。当用户微服务应用系统复杂庞大时,可能具有大量的配置文件,甚至配置文件的格式多样,使用导入导出功能可以帮助用户便捷的设置配置项,快速搬迁应用至CSE。支持配置的监听查询,客户端可以主动发现配置文件的变更,重新读取配置文件内容,秒级生效,实现配置的热更新,无需重新部署应用和服务,让配置管理变得更加高效和敏捷。支持对服务进行管理。 阅读详情

相关推荐

深入解析TMC2209 UART寄存器配置:从基础指令到高级参数调优

本文深入解析TMC2209 UART寄存器配置,从基础指令到高级参数调优,涵盖电流控制、微步细分等关键设置。通过实战案例和优化技巧,帮助开发者高效配置步进电机驱动,提升系统性能和稳定性。特别介绍了UART通信协议和CRC校验实现,确保数据传输可靠性。

tequila的博客 1161

5分钟搞定Dubbo应用接入华为云微服务引擎CSE

Dubbo to 华为云微服务引擎CSE 迁移指南Dubbo和Java chassis底层都使用了Spring的依赖注入和bean管理系统,所以使用Dubbo的服务迁移到ServiceComb工作量较小, 主要改动在依赖和配置方面。本示例的Dubbo DEMO来源于dubbo官网。目录dubbo-demo是原始的DEMO,dubbo-demo-servicecomb是改造后的DEMO。服务提供方替...

微服务技术与实践专栏 3012

FRM模型五:Brinson业绩归因

利用Brinson对基金组合业绩进行归因分析。

stonesssssss的博客 3022

CSE RPC流程分析

编码:RegistrationManager-》ServiceCenterRegistration-》RegistryUtils层层递进,结构清晰,SCBEngine中做统一的管理。在上面第4步中,由于cse core模块中定义了如下microservice.yaml,因此默认不使用filter-chains。1、首先执行hello.sayHi(“Java Chassis”)方法,会进入代理类的invoke方法中。最终rpc调用通过vertx实现的http请求发送给provider执行。

qq_32907491的博客 1450

工程师必看:如何用定时截尾试验快速验证产品MTBF(附真实案例解析)

本文为硬件工程师详细解析了如何运用定时截尾试验快速验证产品MTBF(平均无故障工作时间)。通过七步实战法,结合工业物联网网关的真实案例,阐述了从参数设定、试验执行到结果判读的完整流程,并提供了MATLAB脚本实现自动化计算与可视化,帮助工程师在有限时间内科学评估产品可靠性。

weixin_29243063的博客 508

C#与Lua交互原理

以前每一次研究一些新知识并且有所收获的时候,都想写一篇博客来分享这种自己的收获。 一直没有写主要是因为自己水平太菜了,怕写出来贻笑大方,最近想通了,想写就写下来,就算对别人毫无用处,还可以自己没事翻翻,省得自己都忘了。当然如果能对你有一丝丝的帮助,那真是再好不过了 。本文将针对C#与Lua的调用原理阐述一些个人的心得 。 Lua开发环境搭建 有关于VS &amp...

Hui Ye的博客 1万+

初识ServiceComb

初识ServiceComb一、什么是ServiceComb二、ServiceComb的使用2.1 Service-Center注册中心2.2 搭建ServiceComb项目2.3 ServiceComb配置欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你

ShootingStar_1998的博客 2698

告别盲调!用Synopsys VIP搭建PCIe 5.0验证环境,手把手搞定链路训练与均衡调试

本文详细介绍了基于Synopsys VIP搭建PCIe 5.0验证环境的实战指南,重点解析了链路训练(LTSSM)与均衡调试的关键技术。通过配置VIP组件、设计验证平台架构及实战调试技巧,帮助工程师高效解决PCIe 5.0验证中的常见问题,提升芯片验证效率与可靠性。

weixin_28700411的博客 467

华为云微服务引擎CSE事务方案一:TCC机制的数据最终一致性处理

TCC机制的数据最终一致性处理概念阐述在一个长事务中,一个由两台服务器一起参与的事务,服务器A发起事务,服务器B参与事务,B的事务需要人工参与,所以处理时间可能很长。如果按照ACID的原则,要保持事务的隔离性、一致性,A发起的事务中使用到的事务资源将会被锁定,不允许其他应用访问到事务过程中的中间结果,直到整个事务被提交或者回滚。这就造成事务A中的资源被长时间锁定,系统将不可用。为了解决在事务运行过...

微服务技术与实践专栏 1210

Java写一条吃满屏幕的贪吃蛇(A*自动寻路算法和一些简单的策略) 二

上一篇文章介绍了一条贪吃蛇的简单实现,这一篇介绍贪吃蛇的自动寻路算法 ,说是自动寻路其实也就是一种遍历地图的算法,如果玩过游戏肯定知道游戏里面一般会有自动寻路功能,贪吃蛇的自动寻路算法也就是实现这个功能。下面慢慢介绍这种算法吧。    最开始,我没有在网上找资料的时候,我对于设计寻路算法的看法是遍历整个地图,将障碍物做上标记,然后找一条能够到达目的地的线路就可以了。所以最开始我用了特别暴力的方式来...

Sober_yang的博客 3637

电阻抗成像肺功能测试数据分析与直方图生成

本文介绍了基于MATLAB的电阻抗成像(EIT)肺功能测试数据分析方法。研究针对32×32像素的EIT图像序列,通过三步算法处理:首先计算特定时间点与谷值图像的差值,然后分析1秒后峰值与1秒值的差值,最终计算比值矩阵并处理异常值。系统展示了数据预处理、关键时间点检测、比值计算及统计分析的全流程,包括生成概率分布直方图和空间分布图等可视化方法。该分析为无创肺功能评估提供量化指标,可应用于临床呼吸监测和疾病诊断。

huanghm88的专栏 204

华为云PaaS平台微服务治理3微服务引擎CSE

3微服务引擎CSE 3.1华为云PaaS平台介绍 华为云PaaS平台以华为FusionStage2.0项目为基础,基于Docker、Kubernetes等主流开源容器项目,提供了开 发、测试、部署、运维的全流程自动化流水线能力,提供先进的微服务框架和丰富的服务组件,致力于让开发者专 注于代码开发本身,提升开发效率,支持丰富的应用生态,推动企业更好的云化转型。 什么是PaaS? PaaS是云计算...

kai46385076的专栏 4958

OpenHarmony WebView引擎:从Chromium魔改到分布式渲染的终极解析

ArkWeb框架提供了强大的Web应用开发能力,但同时也需要注意网络安全问题,尤其是跨域请求方面。

m0_67505153的博客 1203

华为云CSE 关键特性,支持托管Nacos注册配置中心

作为服务注册发现中心,CSE Nacos正常情况下只会给服务消费者返回健康的服务提供者实例,当用户应用访问量激增,所有的调用都只会转发到健康实例,可能导致服务的崩溃,产生雪崩效应。当用户微服务应用系统复杂庞大时,可能具有大量的配置文件,甚至配置文件的格式多样,使用导入导出功能可以帮助用户便捷的设置配置项,快速搬迁应用至CSE。支持配置的监听查询,客户端可以主动发现配置文件的变更,重新读取配置文件内容,秒级生效,实现配置的热更新,无需重新部署应用和服务,让配置管理变得更加高效和敏捷。支持对服务进行管理。

m0_74409725的博客 649

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

先抛出疑问,待后续研究:华为service mesher如何改造旧有的使用RPC框架提供服务的项目,比如dubbo,或者公司自研的RPC框架

我们知道,旧有的项目想要接入华为CSE,使用微服务的功能,比如,服务注册发现,负载均衡,熔断,限流等,可以使用service mesh的理念,通过类似网络代理,将旧有项目接入CSE,与网络代理组合,形成逻辑上的微服务。 如果旧项目作为服务的提供方,使用REST方式提供服务,那我们很容易通过编写OPENAPI契约,植入mesher,消费方请求服务,通过mesher转发,根据契约请求服务提供方。 ...

a469517790的博客 449

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

应用系统迁移华为云评估

本文主要尝试回答两个问题: ·客户运行在其他云平台(比如阿里云)的应用系统,如何搬迁到华为云,如何评估搬迁的可行性和工作量,具体方案是什么以及有什么优缺点。 ·针对客户担心的“如何避免被云厂商”绑定的顾虑,客户应该如何选择更好的技术架构来应对。 回答这两个问题并不容易,在考虑“云原生”、“微服务”等新概念的时候,不仅仅是一个技术导向的问题,还涉及到业务、组织和管理等方面的调整。本文会把问题缩...

weixin_44829191的博客 1081

深度学习工具包 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")

【分布式利器:腾讯TSF】11、腾讯TSF微服务框架深度对比:全面解析TSF vs Spring Cloud vs Dubbo vs Service Mesh

腾讯TSF微服务框架深度对比分析 本文从架构演进、核心特性、部署运维等维度全面对比了腾讯TSF与Spring Cloud、Dubbo等主流微服务框架。TSF作为云原生全托管解决方案,采用分层架构设计,集成服务治理、配置管理、监控告警等核心能力,相比开源框架具有显著优势:1)一体化平台简化了组件集成复杂度;2)全托管服务降低运维成本;3)统一控制面提升管理效率。性能测试显示,TSF在资源消耗和服务治理能力上优于传统方案,特别适合上云企业快速构建微服务体系。文章通过架构图、流程图和对比表格,为技术选型提供了清晰

2025博客之星Top81。专注AI工程化与架构实战。从分布式思维到模型部署,用工程化视角为你厘清AI落地的真实路径。 2372

【华为云分享】应用系统迁移华为云评估

本文主要尝试回答两个问题: 客户运行在其他云平台(比如阿里云)的应用系统,如何搬迁到华为云,如何评估搬迁的可行性和工作量,具体方案是什么以及有什么优缺点。 针对客户担心的“如何避免被云厂商”绑定的顾虑,客户应该如何选择更好的技术架构来应对。 回答这两个问题并不容易,在考虑“云原生”、“微服务”等新概念的时候,不仅仅是一个技术导向的问题,还涉及到业务、组织和管理等方面的调整。本文会把问题缩小到技...

华为云官方博客 3193

微服务改造设计参考

【摘要】 本文总结微服务改造相关的可行性分析、工作量评估、设计思路等问题,供选型参考。典型的场景包括将Servlet应用改造为CSE、Dubbo改造为CSE、Spring Cloud改造为CSE等。同时给开发者提供了一些开发建议,使得自己的业务系统能够更好的切换开发框架。 本文总结微服务改造相关的工作量评估、设计思路等问题,供选型参考。典型的场景包括将Servlet应用改造为CSE、Dubbo改...

华为云官方博客 1656

华为云微服务治理方案

华为云微服务方案:华为云PaaS平台介绍、微服务引擎CSE、Edge Service、云容器CCE

学习记录和总结 1万+

云原生架构优化——架构改造迁移

微服务Apache Dubbo架构改造Spring Cloud架构,并迁移上华为云。

weixin_53439529的博客 902

远程调用(REST和RPC)

远程调用的几种方法

须臾徐的博客 2076
上一篇: 跟我学CSE系列之5:Spring Cloud应用如何接入华为云微服务引擎CSE
下一篇: 让.NET应用秒变微服务
looook
博客等级 码龄20年 147粉丝 195原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址