SmartCode.ETL 这不是先有鸡还是蛋的问题!

继国庆节 SmartCode 正式版(SmartCode.Generator)发布之后,SmartCode 迎来了新的能力 SmartCode.ETL !

SmartCode 正式版从开始发布就从未说过自己仅仅是个代码生成器,这点上从我第一次宣布SmartCode正式开源的文章就可以说明:《SmartCode 不只是代码生成器》,这不仅仅是一句推广语!

SmartCode.Generator

相信不少同学都用过各种代码生成器,这里我就不做详细介绍了,如果想体验 SmartCode.Generator 请至 https://www.cnblogs.com/Ahoo-Wang/p/SmartCode-intro.html 配置好数据库连接,一键生成解决方案。

Why SmartCode.ETL

相信不少已经落地微服务架构方案的同学都会遇到同样的问题:

  1. 业务方的查询需求似乎总是跨微服务DB的

  2. 领导层需要查看的报表数据总是全局的(需要聚合跨微服务DB的)

So SmartCode.ETL

  1. 从多个微服务DB 同步业务聚合查询数据到 all_biz DB (解决:微服务架构一定会遇到的业务方需要跨微服务DB查询的问题)

  2. 从 all_biz DB 同步聚合分析数据到 report DB (解决:领导层查看的报表数据聚合问题)

How SmartCode.ETL

  1. 安装 SmartCode from dotnet-cli

    dotnet tool install --global SmartCode.CLI
  2. 使用 SmartCode.Generator 生成 同步Sql表结构脚本,以及 SmartCode.ETL 构建配置

  3. 执行Sql同步脚本初始化表结构

  4. 使用任务调度(crontab) + SmartCode.ETL 同步分析数据

  5. 通过持久化 etl_task 监控 etl执行情况(目前支持PostgreSql)

简单来说就是SmartCode生成SmartCode,任务调度执行SmartCode命令行。(这真的不是先有鸡还是蛋的问题.....)

SmartCode 插件概览

{  "SmartCode": {    "Version": "v1.16.15",    "Plugins": [{        "Type": "SmartCode.IDataSource,SmartCode",        "ImplType": "SmartCode.NoneDataSource,SmartCode"},{        "Type": "SmartCode.IBuildTask,SmartCode",        "ImplType": "SmartCode.App.BuildTasks.ClearBuildTask,SmartCode.App"},{        "Type": "SmartCode.IBuildTask,SmartCode",        "ImplType": "SmartCode.App.BuildTasks.ProjectBuildTask,SmartCode.App"},{        "Type": "SmartCode.IBuildTask,SmartCode",        "ImplType": "SmartCode.App.BuildTasks.MultiTemplateBuildTask,SmartCode.App"},{        "Type": "SmartCode.IBuildTask,SmartCode",        "ImplType": "SmartCode.App.BuildTasks.ProcessBuildTask,SmartCode.App"},{        "Type": "SmartCode.IOutput,SmartCode",        "ImplType": "SmartCode.App.Outputs.FileOutput,SmartCode.App"},{        "Type": "SmartCode.IDataSource,SmartCode",        "ImplType": "SmartCode.Generator.DbTableSource,SmartCode.Generator"},{        "Type": "SmartCode.IBuildTask,SmartCode",        "ImplType": "SmartCode.Generator.BuildTasks.TableBuildTask,SmartCode.Generator"},{        "Type": "SmartCode.IBuildTask,SmartCode",        "ImplType": "SmartCode.Generator.BuildTasks.SingleBuildTask,SmartCode.Generator"},{        "Type": "SmartCode.INamingConverter,SmartCode",        "ImplType": "SmartCode.Generator.TableNamingConverter,SmartCode.Generator"},{        "Type": "SmartCode.TemplateEngine.ITemplateEngine,SmartCode.TemplateEngine",        "ImplType": "SmartCode.TemplateEngine.Impl.HandlebarsTemplateEngine,SmartCode.TemplateEngine"},{        "Type": "SmartCode.TemplateEngine.ITemplateEngine,SmartCode.TemplateEngine",        "ImplType": "SmartCode.TemplateEngine.Impl.OfficialRazorTemplateEngine,SmartCode.TemplateEngine"},{        "Type": "SmartCode.Generator.IDbTypeConverter,SmartCode.Generator",        "ImplType": "SmartCode.Generator.DbTypeConverter.DefaultDbTypeConverter,SmartCode.Generator"},{        "Type": "SmartCode.IDataSource,SmartCode",        "ImplType": "SmartCode.ETL.ExtractDataSource,SmartCode.ETL"},{        "Type": "SmartCode.IBuildTask,SmartCode",        "ImplType": "SmartCode.ETL.BuildTasks.TransformBuildTask,SmartCode.ETL"},{        "Type": "SmartCode.ETL.ITransformEngine,SmartCode.ETL",        "ImplType": "SmartCode.ETL.TransformEngine.RazorTransformEngine,SmartCode.ETL"},{        "Type": "SmartCode.IBuildTask,SmartCode",        "ImplType": "SmartCode.ETL.BuildTasks.LoadBuildTask,SmartCode.ETL"},{        "Type": "SmartCode.ETL.IETLRepository,SmartCode.ETL",        "ImplType": "SmartCode.ETL.NoneETLRepository,SmartCode.ETL"},{        "Type": "SmartCode.ETL.IETLRepository,SmartCode.ETL",        "ImplType": "SmartCode.ETL.PostgreSql.PGETLRepository,SmartCode.ETL.PostgreSql",        "Paramters": {          "ConnectionString": "Server=localhost;Port=5432;User Id=postgres;Password=SmartSql; Database=smartcode_etl;"}}]}
}

ETL 构建配置

Author: Ahoo WangDataSource:  Name: Extract  Paramters:    DbProvider: SqlServer    ConnectionString: Data Source=.;Initial Catalog=SmartSqlDB;Integrated Security=True   
Query:
SELECT [Id],[UserName],[Status],[LastLoginTime],[CreationTime],[ModifyTime],[Deleted] FROM [T_User] With(NoLock) Where ModifyTime>@LastMaxModifyTime    PKColumn: Id    AutoIncrement: true    ModifyTime: ModifyTimeParamters:  ETLCode: SmartCode.ETL.Test  ETLRepository: PGBuild:  Transform:    Type: Transform    Paramters:      Script:  Load2PostgreSql:    Type: Load    Paramters:      DbProvider: PostgreSql      ConnectionString: Server=localhost;Port=5432;User Id=postgres;Password=SmartSql; Database=smartsql_db;    

Table:
t_user__temp      PreCommand: CREATE TABLE t_user__temp( LIKE t_user );      PostCommand: "Delete From t_user as source Where EXISTS(select * from t_user__temp temp where temp.id=source.id);Insert Into t_user  SELECT * From t_user__temp;Drop Table t_user__temp;"      ColumnMapping: [{Column: Id,Mapping: id},{Column: UserName,Mapping: user_name},{Column: Status,Mapping: status},{Column: LastLoginTime,Mapping: last_login_time},{Column: CreationTime,Mapping: creation_time},{Column: ModifyTime,Mapping: modify_time},{Column: Deleted,Mapping: deleted}]

根 Paramters

参数名说明
ETLCodeETL任务Code,区分任务类型,唯一
ETLRepositoryETL任务持久化仓储,None/PG

DataSource 参数说明

属性 Name:Extract,使用 ExtractDataSource 插件作为数据源

ExtractDataSource.Paramters

参数名说明
DbProvider数据驱动提供者:MySql,MariaDB,PostgreSql,SqlServer,Oracle,SQLite
ConnectionString连接字符串
Query查询命令,需要抽取的数据。默认会自动注入三个参数 LastMaxId,LastMaxModifyTime,LastQueryTime 作为查询条件
PKColumn主键列名
AutoIncrement是否为自增主键,true 自动计算抽取的最大主键值(MaxId)
ModifyTime最近一次修改时间列名,设置后自定计算抽取的最大修改时间列(MaxModifyTime)

Build.Load 参数说明

属性 Type:Load,使用 LoadBuildTask 插件作为构建任务

Build.Load.Paramters

参数名说明
DbProvider数据驱动提供者:MySql,MariaDB,PostgreSql,SqlServer,Oracle,SQLite
ConnectionString连接字符串
Table目标表名
PreCommand执行批量插入任务之前执行的命令
PostCommand执行批量插入任务之后执行的命令
ColumnMapping列映射

同步策略

LastMaxId

LastMaxId 即上一次抽取的数据最大Id值(第一次抽取时LastMaxId为-1),该模式使用于数据插入后不再变更的数据表。

LastMaxModifyTime

LastMaxModifyTime 即上一次抽取的数据最大ModifyTime值(第一次抽取时LastMaxModifyTime为1970-01-01 08:00:00),适用于插入数据后还会变更的数据表。

并发任务同步

  1. 对 Id 取模,分拆不同任务,同时并发执行

大数据量同步

  1. 使用 Top/Limit 限制数据抽取数量,分多次同步执行完成整个数据同步。

ETL_Task 任务监控

640?wx_fmt=png

性能监控

运行环境
  1. 源抽取库:Windows Server 2012 , 8 vCPU 16 GB + SSD + SqlServer-2014

  2. 目标分析库:CentOS-7 , 8 vCPU 16 GB + SSD + PostgreSql-11 + SmartCode

ETL_Task.Extract

以下是数据抽取性能,抽取数量为 1434678,耗时 41267 毫秒。

{    "MaxId": 1755822,    "PKColumn": "Id",    "QuerySize": 1434678,    "QueryTime": "2018-11-01T11:31:53.6191084+08:00",    "QueryCommand": {        "Taken": 41267,        "Command": "Select * From T_ProductSearchLog  With(NoLock) Where Id>@LastMaxId",        "Paramters": {            "LastMaxId": -1,            "LastQueryTime": "1970-01-01T08:00:00"}}
}
ETL_Task.Load

以下是数据加载性能,批量插入数据量为 1434678,耗时 21817 毫秒,平均每秒插入 65759.6 条数据。

{    "Size": 1434678,    "Table": "t_product_search_log",    "Taken": 21817,    "PreCommand": null,    "PostCommand": null}

目前 SmartCode.ETL 已经落地到我们的生产环境了(11-01上线截至目前执行了 26069 次同步任务,暂无error日志抛出)

PS: 虽然 SmartCode.ETL 只花了周末俩天时间完成扩展,但已经可以满足我们至少90%的应用场景。这足以见得 SmartCode 扩展能力是多么令人意外了。当然SmartCode的其他能力还得后续等各位一起发掘!!!

相关文章:

  • 如何通过本地化事件正确实现微服务内部强一致性,事件总线跨微服务间最终一致性

  • SmartCode 正式开源,不只是代码生成器!

  • SmartSql For Asp.Net Core 最佳实践

  • SmartSql 动态代理仓储

  • SmartCode 常见问题

原文地址:https://www.cnblogs.com/Ahoo-Wang/p/SmartCode-ETL.html

.NET社区新闻,深度好文,欢迎访问公众号文章汇总 http://www.csharpkit.com

640?wx_fmt=jpeg

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

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

相关文章

codeforces1469 E. A Bit Similar

E. A Bit Similar 代码抄的这份题解 找到一个长度为k的串使得在s长度为k的子串中,对于所有子串答案串都至少有一位相同。也就是如果将s长度为k的子串全部按位取反,那么答案串不能与这些反串匹配。 现在问题转化成,找到一个答案串&#xff…

对拍

参考博客 晚上不想刷题。。无聊的开始研究对拍 以前oi的时候看过对拍,奈何当时水平太差根本用不上对拍,(现在水平也不咋地。。) 上面那个博文讲的非常好。。 对拍最终的就是 对拍程序.bat 首先第一步:生成一组输入数据…

P7444-「EZEC-7」猜排列【dp】

正题 题目链接:https://www.luogu.com.cn/problem/P7444 题目大意 一个长度为nnn的排列,已知每个cic_ici​表示那个排列中mexmexmex为iii的区间个数。求满足条件的排列个数 1≤n≤5105,ci≥0,∑i1ncin(n1)2−11\leq n\leq 5\times 10^5,c_i\geq 0,\sum_{i1}^nc_i\…

dubbo线程池为什么耗尽

文章概述 大家可能都遇到过DUBBO线程池打满这个问题,报错如下,本文我们就一起分析DUBBO线程池打满这个问题。 cause: org.apache.dubbo.remoting.RemotingException: Server side(10.0.0.100,20881) thread pool is exhausted, detail msg:Thread pool …

手把手教你写DI_0_DI是什么?

DI是什么?Dependency Injection 常常简称为:DI。它是实现控制反转(Inversion of Control – IoC)的一个模式。fowler 大大大神 “几十年”前的经典文章 https://www.martinfowler.com/articles/injection.html 说的很清楚。“几十…

C++顺序创建txt文件

今天下午在对拍数据的时候感觉好麻烦。。 一次次手调文件名称&#xff0c;突然想起可以直接写段程序集中操作 顺序输出 #include <iostream> #include <fstream> #include<string> using namespace std;int main () {ofstream File;for(int i0;i<3;i){str…

【模板】字符串哈希

ACM模板 目录构建应用构建 字符串哈希就是将字符串映射成一个数&#xff0c;哈希冲突是不可避免的&#xff0c;我们需要选用合适的base尽可能使得哈希冲突可能性降低 unsigned long long溢出后相当于取模&#xff0c;相当于模264−12^{64}-1264−1 get(l,r)函数返回字符串下标…

P5137-polynomial【倍增】

正题 题目链接:https://www.luogu.com.cn/problem/P5137 题目大意 TTT组数据给出n,a,b,pn,a,b,pn,a,b,p求 (∑01naibn−i)%p\left(\sum_{01}^na^ib^{n-i}\right)\%p(01∑n​aibn−i)%p 1≤T≤105,1≤n,a,b,p≤10181\leq T\leq 10^5,1\leq n,a,b,p\leq 10^{18}1≤T≤105,1≤n,a…

使用Visual Studio Code开发.NET Core看这篇就够了

在本文中&#xff0c;我将带着大家一步一步的通过图文的形式来演示如何在Visual Studio Code中进行.NET Core程序的开发&#xff0c;测试以及调试。尽管Visual Studio Code的部分功能还达不到Visual Studio的水平&#xff0c;但它实际上已经足够强大来满足我们的日常开发。而且…

【模板】最大权闭合图

ACM模板 目录概念建图证明模板题概念 闭合图中所有的点的出边必须指向内部的点 建图 原图的边在网络流中的边容量是INF&#xff0c;如果点权是正&#xff0c;那么源点向其连边&#xff0c;容量是点权&#xff1b;否则它向汇点连边&#xff0c;容量是点权绝对值 证明 考虑最…

P4707-重返现世【dp,数学期望,扩展min-max容斥】

正题 题目链接:https://www.luogu.com.cn/problem/P4707 题目大意 nnn个物品&#xff0c;每次生成一种物品&#xff0c;第iii个被生成的概率是pim\frac{p_i}{m}mpi​​&#xff0c;求生成至少kkk种物品的期望次数。 1≤n≤1000,max{n−10,1}≤k≤n,1≤m≤100001\leq n\leq 100…

手把手教你写DI_3_小白徒手支持 Singleton 和 Scoped 生命周期

在上一节&#xff1a;手把手教你写DI_2_小白徒手撸构造函数注入浑身绷带的小白同学&#xff1a;我们继续开展我们的工作&#xff0c;大家都知道 Singleton是什么&#xff0c;就是全局只有一个呗&#xff0c;我们就先从它开始&#xff0c;这个多简单&#xff0c;我们找个字典放这…

监视任务

来源&#xff1a;牛客网 &#xff1a; 时间限制&#xff1a;C/C 2秒&#xff0c;其他语言4秒 空间限制&#xff1a;C/C 131072K&#xff0c;其他语言262144K 64bit IO Format: %lld 题目描述 &#x1d445;&#x1d452;&#x1d458;&#x1d456;在课余会接受一些民间的鹰眼…

【模板】最大密度子图

ACM模板 目录概念做法例题概念 选择一个子图G′(V′,E′)G(V,E)G′(V′,E′)&#xff0c;其中对于任意一条边的两个端点必须在所选的点集中&#xff0c;最大化∣E′∣∣V′∣\frac{|E|}{|V|}∣V′∣∣E′∣​ 做法 利用01分数规划二分即最大化 ∣E′∣−g∣V′∣|E|-g|V|∣E…

牛客练习赛79E-小G的数学难题【dp,单调队列】

正题 题目链接:https://ac.nowcoder.com/acm/contest/11169/E 题目大意 给出nnn个三元组(ai,bi,ci)(a_i,b_i,c_i)(ai​,bi​,ci​)。 要求选出一个集合SSS&#xff0c;要求 (∑i∈Sai)≤P,(∑i∈Sbi)≥P\left(\sum_{i\in S}a_i\right)\leq P,\left(\sum_{i\in S}b_i\right)\…

手把手教你写DI_2_小白徒手撸构造函数注入

在上一节&#xff1a;手把手教你写DI_1_DI框架有什么&#xff1f;我们已经知道我们要撸哪些东西了那么我们开始动工吧&#xff0c;这里呢&#xff0c;我们找小白同学来表演下小白同学 &#xff1a;我们先定义一下我们的广告招聘纸有什么&#xff1a;好&#xff0c;我们实现两种…

E. Pattern Matching(题意理解+拓扑排序)

E. Pattern Matching 首先p[mtj]p[mt_j]p[mtj​]必须能够匹配所给字符sjs_jsj​&#xff0c;然后把所有能够匹配的sjs_jsj​的其他模板串也找出来&#xff0c;这些必须放在p[mtj]p[mt_j]p[mtj​]的后面&#xff0c;典型拓扑排序&#xff0c;连边然后排序即可 #define IO ios:…

Sum

链接&#xff1a;https://ac.nowcoder.com/acm/problem/14269 来源&#xff1a;牛客网 时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒 空间限制&#xff1a;C/C 131072K&#xff0c;其他语言262144K 64bit IO Format: %lld 题目描述 考虑维护一个这样的问题&#xff1a…

NOI.AC#2266-Bacteria【根号分治,倍增】

正题 题目链接:http://noi.ac/problem/2266 题目大意 给出nnn个点的一棵树&#xff0c;有一些边上有中转站&#xff08;边长度为222&#xff0c;中间有一个中转站&#xff09;&#xff0c;否则就是边长为111。 mmm次询问一个东西从xxx出发走到yyy&#xff0c;每隔kkk步中转站…

服务器win2008 R2 x64 部署ASP.net core到IIS 并解决 HTTP Error 502.5 的问题

1、发布网站 &#xff1b;2、安装 vc_redist.x64 (Visual C Redistributable for Visual Studio 2015) 新装的系统没装的补丁&#xff0c;装过略过&#xff1b;3、安装WindowsHosting &#xff1a;如&#xff1a; dotnet-hosting-2.1.3-win &#xff1b;4、安装.Net Core SDK&…