Cloud stream computing, online business, closed-loop design for real-time analysis - Alibaba Cloud RDS, HybridDB for PostgreSQL Best Practices

Click to read the original text

Abstract:  The flow of background water merges into rivers and seas, nurtures life and forms natural ecology. Data flows, promotes social progress, and expands business boundaries. "Insight into the Importance of Data Flow from Human River Civilization" is based on a business case of Taobao, and see how users can use Alibaba Cloud RDS PostgreSQL, HybridDB for PostgreSQL, and massive object storage OSS to create a business from stream computing to online business, and then to Data analysis and mining business, play the value of data, expand the boundaries of business.

background

The flow of water merges into rivers and seas, nurtures life and forms a natural ecology. Data flows, promotes social progress, and expands business boundaries.

"The Importance of Insights into Data Flow from Human River Civilization"

Take a business case from Taobao to see how users can use Alibaba Cloud RDS PostgreSQL, HybridDB for PostgreSQL, and massive object storage OSS to create a business from stream computing to online business, to data analysis and mining, and to give full play to the value of data. Extend the boundaries of your business.

Business Profile

An e-commerce business usually involves the roles of merchants, stores, logistics, users, payment channels, loan channels, commodities, platforms, secondary schools, advertisers, manufacturers, distributors, store owners, store clerks, supervisors, taxation, quality inspection, etc. .

The activities of these objects will generate a large amount of data on browsing, orders, complaints, refunds, disputes, etc.

Platform business goals:

According to the data of these objects, real-time analysis, real-time public opinion display, real-time identification of objects that need active service, etc. It belongs to an intelligent service operation platform.

Architecture

To achieve the goal of an "intelligent service operation platform", we need to aggregate the relevant behaviors and dictionary data generated by each business line in quasi-real-time for unified real-time analysis.

pic

1. Data source

The data sources are databases or real-time logs, message queues, relational databases, stream computing platforms, etc. from various business lines.

2. Real-time analysis database

For real-time analytical database, choose Alibaba Cloud HybridDB for PostgreSQL is a distributed real-time analytical database based on Greenplum's open source version GPDB. It supports PB-level data volume, supports row-column mixed storage, supports compression, and supports update.

已有互联网、金融、国家安全等行业大量用户案例。

OLAP语法支持全面。阿里云HDB在开源基础上还增加了JSON,估值类型HLL的支持。同时内核层面进行了优化,增加了LLVM,SORTKEY,METADATA,OSS外部表,MADLIB机器学习库 等特性,大幅提升分析型SQL的性能。

3、调度平台

HDB for PostgreSQL是一个分析型的数据库,为分析场景设计,虽然支持单条INSERT的写入,但是性能最好的依旧是并行的数据灌入。比如使用阿里云HybridDB for PostgreSQL的OSS外部表功能,从阿里云OSS对象存储并行的导入数据。

由于数据来源多,写入并发高,所以建议的做法是通过调度的方法,准实时的将数据合并然后并行写入到HybridDB for PostgreSQL

同时对于一些状态数据,实际上业务仅需最新的一条,所以单条INSERT也会增加数据的写入量。因此我们会增加一个实时合并数据的数据库。

4、实时合并数据库

实时合并数据库的设计目标:

可以接受高并发的写入,同时支持数据合并,支持直接将数据写入OSS对象存储。

在阿里云中对应的是RDS PostgreSQL产品。它可以支持非常高并发的数据写入(单实例可以达到几百万行/s的写入速度),同时支持将数据并发的写入OSS对象存储。从而实现数据的合并,最终合并到HDB for PostgreSQL的目标。

5、OSS对象存储

阿里云OSS对象存储,与RDS PostgreSQL, HybridDB for PostgreSQL结合,可以实现用户数据的冷热分离,数据中转等功能(作为数据中转时,每个HybridDB for PostgreSQL 目前已支持每个数据节点30MB/s的速度,如果有128个实例,速度就达到了4GB/s)。

OSS海量存储,海量带宽,廉价。

在阿里集团、阿里公有云用户群中已经有大量成熟的案例,通过OSS实现数据库的冷热分离,数据高速中转。

6、BI运营平台

业务方围绕HybridDB for PostgreSQL数据库打造的一个BI平台。运算交给HybridDB for PostgreSQL。

实时合并与调度实施细节

RDS PostgreSQL

RDS PostgreSQL 负责接收实时业务数据,合并业务数据,并将数据写入OSS。

为了实现高效的数据切换和清理(因为作为数据合并的数据库,不需要保留历史数据,只管合并和导出到OSS就好了)。

同时RDB PostgreSQL也可以作为业务方的OLTP业务库来使用。功能强大且稳定性好。

1、需要创建两张表,应用程序往其中的一张表写,通过调度系统来实现导出到OSS和切换表名的动作。

create table feed_log (id int, c1 int, c2 int, info text, crt_time timestamp);  
  
create index idx_feed_log on feed_log (id, crt_time desc);  
  
create table feed_log_shadow (id int, c1 int, c2 int, info text, crt_time timestamp);  
  
create index idx_feed_log_shadow on feed_log (id, crt_time desc);  

2、来源数据写入feed_log

insert into feed_log values (?,?,?,?,?);  

3、调度(将feed_log数据写入OSS)

3.1 切换表名。

begin;  
set lock_timeout='2s';  
alter table feed_log_shadow rename to tmp_feed_log_shadow;  
alter table feed_log rename to feed_log_shadow;  
alter table tmp_feed_log_shadow rename to feed_log;  
end;  

3.2 将feed_log的数据,通过RDS PostgreSQL OSS_EXT外部表接口导入到OSS

begin;  
set lock_timeout='2s';  
lock table feed_log_shadow in ACCESS EXCLUSIVE mode;   
  
drop table if exists oss_ext;  
  
-- 创建外部表语法请参考   
-- https://help.aliyun.com/document_detail/44461.html   
-- https://help.aliyun.com/document_detail/35457.html  
  
create oss_ext ....;       
  
-- 使用窗口查询,将合并后的数据写入外部表,每个PK,取最后一条记录。(取最后一条是业务需求,请读者按自己的需求来)  
insert into oss_ext   
  select id,c1,c2,info,crt_time from   
    (select row_number() over(partition by id order by crt_time desc) as rn, * from feed_log_shadow) t   
  where rn=1;  
  
-- 清除已导入oss的记录  
truncate feed_log_shadow;  
end;  

RDS PostgreSQL的调度步骤结束,接下来就是将OSS的数据合并到HybridDB for PostgreSQL。

HybridDB for PostgreSQL

创建HybridDB for PostgreSQL的全量表,但是业务上的需求是ID唯一。

我们选择ID为分布键,crt_time为分区键,但是分区键的VALUE可能变更,所以后面合并的时候需要注意方法。

create table feed_uniq (id int, c1 int, c2 int, info text, crt_time timestamp)   
with (APPENDONLY=true, BLOCKSIZE=2097152,ORIENTATION=column)   
distributed by (id)   
partition by range (crt_time)   
(   
  start (date '2017-07-01') inclusive   
  end (date '2017-08-01') exclusive   
  every (interval '1 day')   
) ;  

创建HybridDB for PostgreSQL OSS外部表语法请参考

https://help.aliyun.com/document_detail/44461.html

https://help.aliyun.com/document_detail/35457.html

-- 创建HybridDB for PostgreSQL外部表,指向RDS PG导出的OSS对应的目录  
-- 仅需创建一次  
create writeable external table oss_ext ....;    

3.3 导入到HybridDB for PostgreSQL

begin;  
  
-- 合并来自上游的OSS文件到HDB的feed_uniq已有记录  
  
-- update(由于可能涉及到分区字段的跨分区更新,所以拆分成两个步骤delete, insert)  
  
-- delete  
delete from feed_uniq using oss_ext where feed_uniq.id=oss_ext.id;  
  
-- insert(包括更新和实际的新增数据)  
  
insert into feed_uniq (...) select * from oss_ext;  
  
-- 清除oss bucket  
调用OSS API清除对应的oss bucket  

调度系统

将以上的调度事务,写入调度平台,设置好依赖关系,就可以实现增量、准实时的数据写入到HybridDB for PostgreSQL了。

《使用D2工作流在ODPS和HybridDB for PG(Greenplum)间自动同步数据》

阿里云HybridDB for PostgreSQL的内核进化

HybridDB for PostgreSQL作为一款支持冷热分离、线性扩展的分析型数据库,除了具备最基本的数据分析能力,阿里云数据库内核团队还对其进行了功能、性能方面的扩展?

1、OSS 海量外部存储。

通过OSS海量存储,打通了云端所有的数据源,同时通过OSS支持冷热数据分离。

2、HLL估值插件。

在分析场景中,估值计算是一个非常常见的需求,通过HLL估值插件,HDB PG支持了海量数据的高效估值查询。

3、MADlib机器学习插件。

通过MADlib机器学习插件,用户可以使用pivotalR和R语言连接HDB PG,实现R的并行计算。

4、开放plpython编程接口。

用户可以在HDB PG中编写python程序,实现复杂的业务处理逻辑或UDF。

5、PostGIS插件

支持地理位置海量数据的挖掘,例如时间、空间维度的数据挖掘。

6、JSON

采用JSON类型,支持更加灵活数据来源的数据挖掘。

7、SORT KEY

通过SORT KEY,用户可以在不建索引的情况下,实现高效的数据过滤和检索。特别适合分析业务中的历史静态数据。对常用的查询列或排序列进行CLUSTER操作后,通过METASCAN,可以在没有索引的情况下,实现比全表扫描快千倍的性能提升。

8、LLVM

静态编译,用户在对大量数据进行访问或运算时,降低数据库内核层面的开销。(类似电池充电或放电时的内阻开销),内耗降低后,性能有3到5倍的提升。

9、向量计算。(开发中)

利用CPU的向量计算指令,批量处理数据,有10倍左右的性能提升。

10、METASCAN

结合SORT KEY,STATS等元信息,实现页级、存储级的WHERE,PROJECTION等下推。从而减少计算层的数据接收量或处理开销。

11、数据写入支持三角模式,开放式驱动包。(开发中)

利用三角模式,用户可以直接写数据到HDB PG的数据节点,减少MASTER节点的开销,消除直接写入的瓶颈。(现有技术通过OSS消除写入瓶颈)

12、支持云生态圈。包括 ETL云服务、BI云服务 等。

简化用户的开发成本,利用云生态,打造智能的企业数据BI平台,作为企业大数据分析的运算和存储的核心引擎。

13、内置高可用、备份调度。扩容、缩容 一键完成。降低用户的使用成本。

达到的效果

通过这个架构,用户实现了流计算、在线业务、数据分析的业务数据闭环。

将分析时间从天的频率提升到了分钟级别。

小结

利用阿里云的云生态,RDS PostgreSQL,HybridDB for PostgreSQL,对象存储OSS,QuickBI,流计算平台,消息队列,中间件服务等一系列云服务,帮助企业打造智能的企业数据BI平台,HybridDB for PostgreSQL也企业大数据实时分析运算和存储的核心引擎。

实现了企业在云端从流计算、在线业务、到数据实时分析的业务数据闭环。

参考

《从人类河流文明 洞察 数据流动的重要性》

阿里云 RDS PostgreSQL

阿里云 HybridDB for PostgreSQL

《Greenplum 性能评估公式 - 阿里云HybridDB for PostgreSQL最佳实践》

阅读原文请点击

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327037082&siteId=291194637