宇宙湾

厚积薄发

介绍 Antlr 基本概念、特性、工作机制、内部运作流程,以及踩到的一些坑。

阅读全文 »

Nginx 是什么?

Nginx™ [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server

环境搭建

下载

 在 Nginx Archive 下载页面,下载 nginx-1.13.12.tar.gz 安装包

安装依赖

1
2
$ yum -y install openssl openssl-devel
$ yum -y install pcre-devel

编译安装

1
2
3
4
5
$ tar zxvf nginx-1.13.12.tar.gz
# 必须要跳转到 nginx 安装目录下
$ cd nginx-1.13.12
$ ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf
$ make -j4 && make -j4 install

启动

1
2
$ cd /usr/local/nginx/
$ sbin/nginx -c /usr/local/nginx/nginx.conf
1
$ ps -ef | grep nginx
1
2
3
4
root     107034      1  0 Oct31 ?        00:00:00 nginx: master process sbin/nginx
nobody 107036 107034 0 Oct31 ? 00:00:00 nginx: worker process
nobody 107266 107265 0 Oct31 ? 00:00:00 tsar --check --apache --cpu --mem --load --io --traffic --tcp --partition --nginx --swap
root 107270 97588 0 Oct31 pts/1 00:00:00 grep nginx
阅读全文 »

Presto 是什么?

Presto™ (PrestoDB™) is an open source distributed SQL query engine for running interactive analytic queries against data sources of all sizes ranging from gigabytes to petabytes.

Presto™ (PrestoSQL™, a.k.a. Trino™) is a high performance, distributed SQL query engine for big data.

下文将详细介绍二者的区别

基本概念

组件

Coordinator

 负责管理 Worker 和 MetaStore 节点,以及接受客户端查询请求,并进行 SQL 的语法解析(Parser)、执行计划生成与优化(Planner)和查询任务的调度(Scheduler)

Coordinator 通过 RESTful 接口与 Client 和 Worker 交互

Worker

 负责具体的查询计算和数据读写

Discovery Server

 负责发现集群的各个节点,用于节点间心跳监控

一般 Discovery Server 混布在 Coordinator 节点上,也支持单独部署
阅读全文 »

实用技巧

List

1
2
3
4
5
6
7
List(1, 9, 2, 4, 5) span (_ < 3)       // (List(1), List(9, 2, 4, 5))  碰到不符合就结束

List(1, 9, 2, 4, 5) partition (_ < 3) // (List(1, 2), List(9, 4, 5)) 扫描所有

List(1, 9, 2, 4, 5) splitAt 2 // (List(1, 9), List(2, 4, 5)) 以下标为分割点

List(1, 9, 2, 4, 5) groupBy (5 < _) // Map(false -> List(1, 2, 4, 5), true -> List(9)) 分割成 Map 对象,以 Boolean 类型为 Key

Iterator

grouped

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import scala.collection.{AbstractIterator, mutable}
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.BigquerySparkSession._

val conf = new SparkConf()
val builder = SparkSession.builder().config(conf).enableHiveSupport()
val spark = builder.getOrCreateBigquerySparkSession()
val df = spark.sql("use db; select * from table")

val dataset = df.rdd.mapPartitions(iter => {

// 将每个 partition 中的多行数据,以 100 为长度作为一组,进行一次批处理
iter.grouped(100)
.flatMap(rows => {
val records = new mutable.MutableList[String]()
rows.foreach(row => records.add(JSON.toJSONString(row, false)))
records
})
})

val filteredEmptyLine = dataset
.filter(_ != null)
.map(JSON.toJSONString(_, false))
.filter(_.trim.length != 0)
阅读全文 »

介绍

InfluxDB™ is a time series database designed to handle high write and query loads. It is an integral component of the TICK stack. InfluxDB is meant to be used as a backing store for any use case involving large amounts of timestamped data, including DevOps monitoring, application metrics, IoT sensor data, and real-time analytics.

基本概念

DataBase

 类似于传统数据库中的 DataBase 概念

Measurement

 和 OLAP 中广义上的度量概念一致,部分 OLAP 数据库中又称为 Metric

Tag

 和 OLAP 中广义上的维度概念一致,部分 OLAP 数据库中又称为 TagKV

Field

 数值

Timestamp

 时间戳

Points

 数据点

Series

 数据点组成的序列

Retention Policy

 数据过期策略,即 TTL

阅读全文 »