云原生 Serverless Database 使用體驗(yàn)
作者 | 李欣??
彈性擴(kuò)展能力差。Serverless 場(chǎng)景中一個(gè)重要特點(diǎn)是應(yīng)用負(fù)載具有顯著的波峰波谷。當(dāng)面臨流量洪峰時(shí),DBA 又需要手動(dòng)對(duì)集群進(jìn)行擴(kuò)容以避免集群被打爆;而適逢流量低谷時(shí),則需要對(duì)集群進(jìn)行縮容以節(jié)省成本。 運(yùn)維復(fù)雜度高。MySQL 搭建需要進(jìn)行購(gòu)置集群、安裝服務(wù)、管理連接。業(yè)務(wù)上線(xiàn)后還要關(guān)注數(shù)據(jù)安全、服務(wù)可用性、響應(yīng)時(shí)間等等,用于集群運(yùn)維的時(shí)間占比會(huì)變高,無(wú)法把更多的精力專(zhuān)注于業(yè)務(wù)研發(fā)上。 成本高。通常 DBA 需要預(yù)估業(yè)務(wù)規(guī)模來(lái)事先設(shè)定數(shù)據(jù)庫(kù)初始容量,當(dāng)業(yè)務(wù)請(qǐng)求量未達(dá)到預(yù)估值時(shí),集群中的資源會(huì)一直處于閑置狀態(tài),造成資源浪費(fèi)。
Serverless DataBase
完全彈性。可根據(jù)應(yīng)用負(fù)載自動(dòng)彈性擴(kuò)縮容,這一特性可為用戶(hù)帶來(lái)更經(jīng)濟(jì)的計(jì)費(fèi)模式和更絲滑的體驗(yàn)。 按量計(jì)費(fèi)。Serverless 數(shù)據(jù)庫(kù)的使用成本主要來(lái)自于計(jì)算成本和存儲(chǔ)成本。用戶(hù)只需為業(yè)務(wù)實(shí)際產(chǎn)生的存儲(chǔ)單元和響應(yīng)單元付費(fèi),節(jié)省成本。
零運(yùn)維。即開(kāi)即用,無(wú)需管理容量、水位、軟件升級(jí)、內(nèi)核優(yōu)化等運(yùn)維事項(xiàng),真正讓研發(fā)專(zhuān)注于業(yè)務(wù)開(kāi)發(fā)。
表格存儲(chǔ) Tablestore 簡(jiǎn)介

寬表模型主要承載表結(jié)構(gòu)數(shù)據(jù)存儲(chǔ),例如電商訂單數(shù)據(jù)。
消息模型主要承載消息數(shù)據(jù)存儲(chǔ),例如 IM/Feeds 消息。
時(shí)序模型主要承載時(shí)序數(shù)據(jù)存儲(chǔ),例如物聯(lián)網(wǎng)設(shè)備時(shí)序數(shù)據(jù)。
Tablestore 體驗(yàn)
1、準(zhǔn)備工作
(1)創(chuàng)建一個(gè)阿里云賬號(hào),并獲取到阿里云賬號(hào)的 AK。(云賬號(hào) AK 是訪(fǎng)問(wèn)所有云服務(wù)包括 Tablestore 的密鑰,后續(xù)需要通過(guò) AK 來(lái)訪(fǎng)問(wèn) Tablestore 服務(wù))。
首先通過(guò) config 命令配置連接密鑰并通過(guò) enable_service 命令開(kāi)通 Tablestore 服務(wù):
config --id accessKeyID --key accessKeySecretenable_service
create_instance -d "order storage" -n serverless-db -r cn-hangzhou實(shí)例相當(dāng)于 MySQL 數(shù)據(jù)庫(kù)的概念,實(shí)例創(chuàng)建后無(wú)需思慮實(shí)例所在物理機(jī)集群的水位,只需專(zhuān)注開(kāi)發(fā)業(yè)務(wù)邏輯即可。同時(shí)實(shí)例上的讀寫(xiě)和存儲(chǔ)均為按量計(jì)費(fèi),若無(wú)讀寫(xiě)無(wú)存儲(chǔ),實(shí)際則不會(huì)產(chǎn)生任何費(fèi)用。
至此,一個(gè)能夠支持 GB 到 PB 存儲(chǔ)的、無(wú)并發(fā)限制、零運(yùn)維、完全彈性的 Serverless DataBase 就創(chuàng)建完成了。
2、創(chuàng)建表
create_instance -d "order storage" -n serverless-db -r cn-hangzhou3、數(shù)據(jù)導(dǎo)入
import -i orderDataFile -l 1000000Current speed is: 10000 rows/s. Total succeed count 10000, failed count 0.Current speed is: 12600 rows/s. Total succeed count 22600, failed count 0.......Current speed is: 9200 rows/s. Total succeed count 1000000, failed count 0.Import finished, total count is 1000000, failed 0 rows.
4、訂單查詢(xún)
get --pk '["0000005be2b43dd134eae18ebe079774"]'+----------------------------------+-------+--------+---------+-------------+---------------+--------+--------+----------+--------+---------+-------+-------+--------+------------+| order_id | cId | cName | hasPaid | oId | orderTime | pBrand | pCount | pId | pName | pPrice | pType | sId | sName | totalPrice |+----------------------------------+-------+--------+---------+-------------+---------------+--------+--------+----------+--------+---------+-------+-------+--------+------------+| 0000005be2b43dd134eae18ebe079774 | c0015 | 消周五 | false | o0035062633 | 1507519847532 | 小米 | 3 | p0005003 | 小米 6 | 2299.21 | 手機(jī) | s0017 | 售鄭七 | 6897.63 |+----------------------------------+-------+--------+---------+-------------+---------------+--------+--------+----------+--------+---------+-------+-------+--------+------------+
5、訂單檢索與統(tǒng)計(jì)
create_search_index -t order -n order_index{"IndexSetting": null,"FieldSchemas": [{"FieldName": "id","FieldType": "KEYWORD","Index": true,"EnableSortAndAgg": true,"Store": true},{"FieldName": "pName","FieldType": "TEXT","Index": true,"EnableSortAndAgg": false,"Store": true},{"FieldName": "totalPrice","FieldType": "DOUBLE","Index": true,"EnableSortAndAgg": true,"Store": true}...//其他字段]}
select * from `order` wheresName = "售周五" andpBrand = "小米" andpName like "紅米%"limit 3;
+----------------------------------+-------+--------+---------+-------------+---------------+--------+--------+----------+---------+--------+-------+---------------+-------+--------+------------+| id | cId | cName | hasPaid | oId | orderTime | pBrand | pCount | pId | pName | pPrice | pType | payTime | sId | sName | totalPrice |+----------------------------------+-------+--------+---------+-------------+---------------+--------+--------+----------+---------+--------+-------+---------------+-------+--------+------------+| 00001c760c04126da067e90409467c4e | c0022 | 消趙一 | true | o0009999792 | 1494976931954 | 小米 | 3 | p0005004 | 紅米 5s | 499.01 | 手機(jī) | 1494977189780 | s0005 | 售周五 | 1497.03 |+----------------------------------+-------+--------+---------+-------------+---------------+--------+--------+----------+---------+--------+-------+---------------+-------+--------+------------+| 0000d89f46952ac03da71a33c8e83eef | c0012 | 消錢(qián)二 | false | o0024862442 | 1502415559707 | 小米 | 2 | p0005004 | 紅米 5s | 499.01 | 手機(jī) | null | s0015 | 售周五 | 998.02 |+----------------------------------+-------+--------+---------+-------------+---------------+--------+--------+----------+---------+--------+-------+---------------+-------+--------+------------+| 0000f560b62779285e86947f8e8d0e4c | c0008 | 消馮八 | false | o0000826505 | 1490386088808 | 小米 | 1 | p0005004 | 紅米 5s | 499.01 | 手機(jī) | null | s0015 | 售周五 | 499.01 |+----------------------------------+-------+--------+---------+-------------+---------------+--------+--------+----------+---------+--------+-------+---------------+-------+--------+------------+
select pBrand,count(*) from `order` group bypBrand;+--------+----------+| pBrand | count(*) |+--------+----------+| vivo | 162539 |+--------+----------+| 聯(lián)想 | 304252 |+--------+----------+| oppo | 242513 |+--------+----------+| 蘋(píng)果 | 96153 |+--------+----------+| 小米 | 194543 |+--------+----------+
總結(jié)
如對(duì)本文中所述有疑問(wèn)或者希望進(jìn)一步了解表格存儲(chǔ),可以釘釘搜索群號(hào):“23307953”,群內(nèi)提供免費(fèi)的在線(xiàn)專(zhuān)家服務(wù),歡迎加入。

社區(qū)官網(wǎng)

Serverless Devs
http://www.serverless-devs.com/https://github.com/Serverless-Devs/Serverless-Devshttps://serverlessdevs.resume.net.cn/zh-cn/desktop/index.htmlhttp://serverlessdk.oss.devsapp.net/docs/tutorial-dk/intro/react?https://serverlessdevs.resume.net.cn/zhcn/cli/index.htmlhttps://serverlesshub.resume.net.cn/#/hubs/special-view
?點(diǎn)擊原文,即可查看表格存儲(chǔ)詳情!