什么是流处理

如果有 java 使用经验的同学一定会对 java8 的 Stream 赞不绝口,极大的提高了们对于集合类型数据的处理能力。

int sum = widgets.stream()
.filter(w -> w.getColor() == RED)
.mapToInt(w -> w.getWeight())
.sum();

Stream 能让我们支持链式调用和函数编程的风格来实现数据的处理,看起来数据像是在流水线一样不断的实时流转加工,最终被汇总。Stream 的实现思想就是将数据处理流程抽象成了一个数据流,每次加工后返回一个新的流供使用。

Stream 功能定义

动手写代码之前,先想清楚,把需求理清楚是最重要的一步,我们尝试代入作者的视角来思考整个组件的实现流程。首先把底层实现的逻辑放一下 ,先尝试从零开始进行功能定义 stream 功能。

Stream 的工作流程其实也属于生产消费者模型,整个流程跟工厂中的生产流程非常相似,尝试先定义一下 Stream 的生命周期:

  1. 创建阶段/数据获取(原料)
  2. 加工阶段/中间处理(流水线加工)
  3. 汇总阶段/终结操作(最终产品)

下面围绕 stream 的三个生命周期开始定义 API:

创建阶段

为了创建出数据流 stream 这一抽象对象,可以理解为构造器。

我们支持三种方式构造 stream,分别是:切片转换,channel 转换,函数式转换。

注意这个阶段的方法都是普通的公开方法,并不绑定 Stream 对象。

// 通过可变参数模式创建 stream
func Just(items ...interface{}) Stream // 通过 channel 创建 stream
func Range(source <-chan interface{}) Stream // 通过函数创建 stream
func From(generate GenerateFunc) Stream // 拼接 stream
func Concat(s Stream, others ...Stream) Stream

加工阶段

加工阶段需要进行的操作往往对应了我们的业务逻辑,比如:转换,过滤,去重,排序等等。

这个阶段的 API 属于 method 需要绑定到 Stream 对象上。

结合常用的业务场景进行如下定义:

// 去除重复item
Distinct(keyFunc KeyFunc) Stream
// 按条件过滤item
Filter(filterFunc FilterFunc, opts ...Option) Stream
// 分组
Group(fn KeyFunc) Stream
// 返回前n个元素
Head(n int64) Stream
// 返回后n个元素
Tail(n int64) Stream
// 转换对象
Map(fn MapFunc, opts ...Option) Stream
// 合并item到slice生成新的stream
Merge() Stream
// 反转
Reverse() Stream
// 排序
Sort(fn LessFunc) Stream
// 作用在每个item上
Walk(fn WalkFunc, opts ...Option) Stream
// 聚合其他Stream
Concat(streams ...Stream) Stream

加工阶段的处理逻辑都会返回一个新的 Stream 对象,这里有个基本的实现范式

汇总阶段

汇总阶段其实就是我们想要的处理结果,比如:是否匹配,统计数量,遍历等等。

// 检查是否全部匹配
AllMatch(fn PredicateFunc) bool
// 检查是否存在至少一项匹配
AnyMatch(fn PredicateFunc) bool
// 检查全部不匹配
NoneMatch(fn PredicateFunc) bool
// 统计数量
Count() int
// 清空stream
Done()
// 对所有元素执行操作
ForAll(fn ForAllFunc)
// 对每个元素执行操作
ForEach(fn ForEachFunc)

梳理完组件的需求边界后,我们对于即将要实现的 Stream 有了更清晰的认识。在我的认知里面真正的架构师对于需求的把握以及后续演化能达到及其精准的地步,做到这一点离不开对需求的深入思考以及洞穿需求背后的本质。通过代入作者的视角来模拟复盘整个项目的构建流程,学习作者的思维方法论这正是我们学习开源项目最大的价值所在。

好了,我们尝试定义出完整的 Stream 接口全貌以及函数。

接口的作用不仅仅是模版作用,还在于利用其抽象能力搭建项目整体的框架而不至于一开始就陷入细节,能快速的将我们的思考过程通过接口简洁的表达出来,学会养成自顶向下的思维方法从宏观的角度来观察整个系统,一开始就陷入细节则很容易拔剑四顾心茫然。。。

rxOptions struct {
unlimitedWorkers bool
workers int
}
Option func(opts *rxOptions)
// key生成器
//item - stream中的元素
KeyFunc func(item interface{}) interface{}
// 过滤函数
FilterFunc func(item interface{}) bool
// 对象转换函数
MapFunc func(intem interface{}) interface{}
// 对象比较
LessFunc func(a, b interface{}) bool
// 遍历函数
WalkFunc func(item interface{}, pip chan<- interface{})
// 匹配函数
PredicateFunc func(item interface{}) bool
// 对所有元素执行操作
ForAllFunc func(pip <-chan interface{})
// 对每个item执行操作
ForEachFunc func(item interface{})
// 对每个元素并发执行操作
ParallelFunc func(item interface{})
// 对所有元素执行聚合操作
ReduceFunc func(pip <-chan interface{}) (interface{}, error)
// item生成函数
GenerateFunc func(source <-chan interface{}) Stream interface {
// 去除重复item
Distinct(keyFunc KeyFunc) Stream
// 按条件过滤item
Filter(filterFunc FilterFunc, opts ...Option) Stream
// 分组
Group(fn KeyFunc) Stream
// 返回前n个元素
Head(n int64) Stream
// 返回后n个元素
Tail(n int64) Stream
// 获取第一个元素
First() interface{}
// 获取最后一个元素
Last() interface{}
// 转换对象
Map(fn MapFunc, opts ...Option) Stream
// 合并item到slice生成新的stream
Merge() Stream
// 反转
Reverse() Stream
// 排序
Sort(fn LessFunc) Stream
// 作用在每个item上
Walk(fn WalkFunc, opts ...Option) Stream
// 聚合其他Stream
Concat(streams ...Stream) Stream
// 检查是否全部匹配
AllMatch(fn PredicateFunc) bool
// 检查是否存在至少一项匹配
AnyMatch(fn PredicateFunc) bool
// 检查全部不匹配
NoneMatch(fn PredicateFunc) bool
// 统计数量
Count() int
// 清空stream
Done()
// 对所有元素执行操作
ForAll(fn ForAllFunc)
// 对每个元素执行操作
ForEach(fn ForEachFunc)
}

channel() 方法用于获取 Stream 管道属性,因为在具体实现时我们面向的是接口对象所以暴露一个私有方法 read 出来。

// 获取内部的数据容器channel,内部方法
channel() chan interface{}

实现思路

功能定义梳理清楚了,接下来考虑几个工程实现的问题。

如何实现链式调用

链式调用,创建对象用到的 builder 模式可以达到链式调用效果。实际上 Stream 实现类似链式的效果原理也是一样的,每次调用完后都创建一个新的 Stream 返回给用户。

// 去除重复item
Distinct(keyFunc KeyFunc) Stream
// 按条件过滤item
Filter(filterFunc FilterFunc, opts ...Option) Stream

如何实现流水线的处理效果

所谓的流水线可以理解为数据在 Stream 中的存储容器,在 go 中我们可以使用 channel 作为数据的管道,达到 Stream 链式调用执行多个操作时异步非阻塞效果。

如何支持并行处理

数据加工本质上是在处理 channel 中的数据,那么要实现并行处理无非是并行消费 channel 而已,利用 goroutine 协程、WaitGroup 机制可以非常方便的实现并行处理。

go-zero 实现

core/fx/stream.go

go-zero 中关于 Stream 的实现并没有定义接口,不过没关系底层实现时逻辑是一样的。

为了实现 Stream 接口我们定义一个内部的实现类,其中 source 为 channel 类型,模拟流水线功能。

Stream struct {
source <-chan interface{}
}

创建 API

channel 创建 Range

通过 channel 创建 stream

func Range(source <-chan interface{}) Stream {
return Stream{
source: source,
}
}

可变参数模式创建 Just

通过可变参数模式创建 stream,channel 写完后及时 close 是个好习惯。

func Just(items ...interface{}) Stream {
source := make(chan interface{}, len(items))
for _, item := range items {
source <- item
}
close(source)
return Range(source)
}

函数创建 From

通过函数创建 Stream

func From(generate GenerateFunc) Stream {
source := make(chan interface{})
threading.GoSafe(func() {
defer close(source)
generate(source)
})
return Range(source)
}

因为涉及外部传入的函数参数调用,执行过程并不可用因此需要捕捉运行时异常防止 panic 错误传导到上层导致应用崩溃。

func Recover(cleanups ...func()) {
for _, cleanup := range cleanups {
cleanup()
}
if r := recover(); r != nil {
logx.ErrorStack(r)
}
} func RunSafe(fn func()) {
defer rescue.Recover()
fn()
} func GoSafe(fn func()) {
go RunSafe(fn)
}

拼接 Concat

拼接其他 Stream 创建一个新的 Stream,调用内部 Concat method 方法,后文将会分析 Concat 的源码实现。

func Concat(s Stream, others ...Stream) Stream {
return s.Concat(others...)
}

加工 API

去重 Distinct

因为传入的是函数参数KeyFunc func(item interface{}) interface{}意味着也同时支持按照业务场景自定义去重,本质上是利用 KeyFunc 返回的结果基于 map 实现去重。

函数参数非常强大,能极大的提升灵活性。

func (s Stream) Distinct(keyFunc KeyFunc) Stream {
source := make(chan interface{})
threading.GoSafe(func() {
// channel记得关闭是个好习惯
defer close(source)
keys := make(map[interface{}]lang.PlaceholderType)
for item := range s.source {
// 自定义去重逻辑
key := keyFunc(item)
// 如果key不存在,则将数据写入新的channel
if _, ok := keys[key]; !ok {
source <- item
keys[key] = lang.Placeholder
}
}
})
return Range(source)
}

使用案例:

// 1 2 3 4 5
Just(1, 2, 3, 3, 4, 5, 5).Distinct(func(item interface{}) interface{} {
return item
}).ForEach(func(item interface{}) {
t.Log(item)
}) // 1 2 3 4
Just(1, 2, 3, 3, 4, 5, 5).Distinct(func(item interface{}) interface{} {
uid := item.(int)
// 对大于4的item进行特殊去重逻辑,最终只保留一个>3的item
if uid > 3 {
return 4
}
return item
}).ForEach(func(item interface{}) {
t.Log(item)
})

过滤 Filter

通过将过滤逻辑抽象成 FilterFunc,然后分别作用在 item 上根据 FilterFunc 返回的布尔值决定是否写回新的 channel 中实现过滤功能,实际的过滤逻辑委托给了 Walk method。

Option 参数包含两个选项:

  1. unlimitedWorkers 不限制协程数量
  2. workers 限制协程数量
FilterFunc func(item interface{}) bool

func (s Stream) Filter(filterFunc FilterFunc, opts ...Option) Stream {
return s.Walk(func(item interface{}, pip chan<- interface{}) {
if filterFunc(item) {
pip <- item
}
}, opts...)
}

使用示例:

func TestInternalStream_Filter(t *testing.T) {
// 保留偶数 2,4
channel := Just(1, 2, 3, 4, 5).Filter(func(item interface{}) bool {
return item.(int)%2 == 0
}).channel()
for item := range channel {
t.Log(item)
}
}

遍历执行 Walk

walk 英文意思是步行,这里的意思是对每个 item 都执行一次 WalkFunc 操作并将结果写入到新的 Stream 中。

这里注意一下因为内部采用了协程机制异步执行读取和写入数据所以新的 Stream 中 channel 里面的数据顺序是随机的。

// item-stream中的item元素
// pipe-item符合条件则写入pipe
WalkFunc func(item interface{}, pipe chan<- interface{}) func (s Stream) Walk(fn WalkFunc, opts ...Option) Stream {
option := buildOptions(opts...)
if option.unlimitedWorkers {
return s.walkUnLimited(fn, option)
}
return s.walkLimited(fn, option)
} func (s Stream) walkUnLimited(fn WalkFunc, option *rxOptions) Stream {
// 创建带缓冲区的channel
// 默认为16,channel中元素超过16将会被阻塞
pipe := make(chan interface{}, defaultWorkers)
go func() {
var wg sync.WaitGroup for item := range s.source {
// 需要读取s.source的所有元素
// 这里也说明了为什么channel最后写完记得完毕
// 如果不关闭可能导致协程一直阻塞导致泄漏
// 重要, 不赋值给val是个典型的并发陷阱,后面在另一个goroutine里使用了
val := item
wg.Add(1)
// 安全模式下执行函数
threading.GoSafe(func() {
defer wg.Done()
fn(item, pipe)
})
}
wg.Wait()
close(pipe)
}() // 返回新的Stream
return Range(pipe)
} func (s Stream) walkLimited(fn WalkFunc, option *rxOptions) Stream {
pipe := make(chan interface{}, option.workers)
go func() {
var wg sync.WaitGroup
// 控制协程数量
pool := make(chan lang.PlaceholderType, option.workers) for item := range s.source {
// 重要, 不赋值给val是个典型的并发陷阱,后面在另一个goroutine里使用了
val := item
// 超过协程限制时将会被阻塞
pool <- lang.Placeholder
// 这里也说明了为什么channel最后写完记得完毕
// 如果不关闭可能导致协程一直阻塞导致泄漏
wg.Add(1) // 安全模式下执行函数
threading.GoSafe(func() {
defer func() {
wg.Done()
//执行完成后读取一次pool释放一个协程位置
<-pool
}()
fn(item, pipe)
})
}
wg.Wait()
close(pipe)
}()
return Range(pipe)
}

使用案例:

返回的顺序是随机的。

func Test_Stream_Walk(t *testing.T) {
// 返回 300,100,200
Just(1, 2, 3).Walk(func(item interface{}, pip chan<- interface{}) {
pip <- item.(int) * 100
}, WithWorkers(3)).ForEach(func(item interface{}) {
t.Log(item)
})
}

分组 Group

通过对 item 匹配放入 map 中。

KeyFunc func(item interface{}) interface{}

func (s Stream) Group(fn KeyFunc) Stream {
groups := make(map[interface{}][]interface{})
for item := range s.source {
key := fn(item)
groups[key] = append(groups[key], item)
}
source := make(chan interface{})
go func() {
for _, group := range groups {
source <- group
}
close(source)
}()
return Range(source)
}

获取前 n 个元素 Head

n 大于实际数据集长度的话将会返回全部元素

func (s Stream) Head(n int64) Stream {
if n < 1 {
panic("n must be greather than 1")
}
source := make(chan interface{})
go func() {
for item := range s.source {
n--
// n值可能大于s.source长度,需要判断是否>=0
if n >= 0 {
source <- item
}
// let successive method go ASAP even we have more items to skip
// why we don't just break the loop, because if break,
// this former goroutine will block forever, which will cause goroutine leak.
// n==0说明source已经写满可以进行关闭了
// 既然source已经满足条件了为什么不直接进行break跳出循环呢?
// 作者提到了防止协程泄漏
// 因为每次操作最终都会产生一个新的Stream,旧的Stream永远也不会被调用了
if n == 0 {
close(source)
break
}
}
// 上面的循环跳出来了说明n大于s.source实际长度
// 依旧需要显示关闭新的source
if n > 0 {
close(source)
}
}()
return Range(source)
}

使用示例:

// 返回1,2
func TestInternalStream_Head(t *testing.T) {
channel := Just(1, 2, 3, 4, 5).Head(2).channel()
for item := range channel {
t.Log(item)
}
}

获取后 n 个元素 Tail

这里很有意思,为了确保拿到最后 n 个元素使用环形切片 Ring 这个数据结构,先了解一下 Ring 的实现。

// 环形切片
type Ring struct {
elements []interface{}
index int
lock sync.Mutex
} func NewRing(n int) *Ring {
if n < 1 {
panic("n should be greather than 0")
}
return &Ring{
elements: make([]interface{}, n),
}
} // 添加元素
func (r *Ring) Add(v interface{}) {
r.lock.Lock()
defer r.lock.Unlock()
// 将元素写入切片指定位置
// 这里的取余实现了循环写效果
r.elements[r.index%len(r.elements)] = v
// 更新下次写入位置
r.index++
} // 获取全部元素
// 读取顺序保持与写入顺序一致
func (r *Ring) Take() []interface{} {
r.lock.Lock()
defer r.lock.Unlock() var size int
var start int
// 当出现循环写的情况时
// 开始读取位置需要通过去余实现,因为我们希望读取出来的顺序与写入顺序一致
if r.index > len(r.elements) {
size = len(r.elements)
// 因为出现循环写情况,当前写入位置index开始为最旧的数据
start = r.index % len(r.elements)
} else {
size = r.index
}
elements := make([]interface{}, size)
for i := 0; i < size; i++ {
// 取余实现环形读取,读取顺序保持与写入顺序一致
elements[i] = r.elements[(start+i)%len(r.elements)]
} return elements
}

总结一下环形切片的优点:

  • 支持自动滚动更新
  • 节省内存

环形切片能实现固定容量满的情况下旧数据不断被新数据覆盖,由于这个特性可以用于读取 channel 后 n 个元素。

func (s Stream) Tail(n int64) Stream {
if n < 1 {
panic("n must be greather than 1")
}
source := make(chan interface{})
go func() {
ring := collection.NewRing(int(n))
// 读取全部元素,如果数量>n环形切片能实现新数据覆盖旧数据
// 保证获取到的一定最后n个元素
for item := range s.source {
ring.Add(item)
}
for _, item := range ring.Take() {
source <- item
}
close(source)
}()
return Range(source)
}

那么为什么不直接使用 len(source) 长度的切片呢?

答案是节省内存。凡是涉及到环形类型的数据结构时都具备一个优点那就省内存,能做到按需分配资源。

使用示例:

func TestInternalStream_Tail(t *testing.T) {
// 4,5
channel := Just(1, 2, 3, 4, 5).Tail(2).channel()
for item := range channel {
t.Log(item)
}
// 1,2,3,4,5
channel2 := Just(1, 2, 3, 4, 5).Tail(6).channel()
for item := range channel2 {
t.Log(item)
}
}

元素转换Map

元素转换,内部由协程完成转换操作,注意输出channel并不保证按原序输出。

MapFunc func(intem interface{}) interface{}
func (s Stream) Map(fn MapFunc, opts ...Option) Stream {
return s.Walk(func(item interface{}, pip chan<- interface{}) {
pip <- fn(item)
}, opts...)
}

使用示例:

func TestInternalStream_Map(t *testing.T) {
channel := Just(1, 2, 3, 4, 5, 2, 2, 2, 2, 2, 2).Map(func(item interface{}) interface{} {
return item.(int) * 10
}).channel()
for item := range channel {
t.Log(item)
}
}

合并 Merge

实现比较简单,我考虑了很久没想到有什么场景适合这个方法。

func (s Stream) Merge() Stream {
var items []interface{}
for item := range s.source {
items = append(items, item)
}
source := make(chan interface{}, 1)
source <- items
return Range(source)
}

反转 Reverse

反转 channel 中的元素。反转算法流程是:

  • 找到中间节点

  • 节点两边开始两两交换

注意一下为什么获取 s.source 时用切片来接收呢? 切片会自动扩容,用数组不是更好吗?

其实这里是不能用数组的,因为不知道 Stream 写入 source 的操作往往是在协程异步写入的,每个 Stream 中的 channel 都可能在动态变化,用流水线来比喻 Stream 工作流程的确非常形象。

func (s Stream) Reverse() Stream {
var items []interface{}
for item := range s.source {
items = append(items, item)
}
for i := len(items)/2 - 1; i >= 0; i-- {
opp := len(items) - 1 - i
items[i], items[opp] = items[opp], items[i]
}
return Just(items...)
}

使用示例:

func TestInternalStream_Reverse(t *testing.T) {
channel := Just(1, 2, 3, 4, 5).Reverse().channel()
for item := range channel {
t.Log(item)
}
}

排序 Sort

内网调用 slice 官方包的排序方案,传入比较函数实现比较逻辑即可。

func (s Stream) Sort(fn LessFunc) Stream {
var items []interface{}
for item := range s.source {
items = append(items, item)
} sort.Slice(items, func(i, j int) bool {
return fn(i, j)
})
return Just(items...)
}

使用示例:

// 5,4,3,2,1
func TestInternalStream_Sort(t *testing.T) {
channel := Just(1, 2, 3, 4, 5).Sort(func(a, b interface{}) bool {
return a.(int) > b.(int)
}).channel()
for item := range channel {
t.Log(item)
}
}

拼接 Concat

func (s Stream) Concat(steams ...Stream) Stream {
// 创建新的无缓冲channel
source := make(chan interface{})
go func() {
// 创建一个waiGroup对象
group := threading.NewRoutineGroup()
// 异步从原channel读取数据
group.Run(func() {
for item := range s.source {
source <- item
}
})
// 异步读取待拼接Stream的channel数据
for _, stream := range steams {
// 每个Stream开启一个协程
group.Run(func() {
for item := range stream.channel() {
source <- item
}
})
}
// 阻塞等待读取完成
group.Wait()
close(source)
}()
// 返回新的Stream
return Range(source)
}

汇总 API

全部匹配 AllMatch

func (s Stream) AllMatch(fn PredicateFunc) bool {
for item := range s.source {
if !fn(item) {
// 需要排空 s.source,否则前面的goroutine可能阻塞
go drain(s.source)
return false
}
} return true
}

任意匹配 AnyMatch

func (s Stream) AnyMatch(fn PredicateFunc) bool {
for item := range s.source {
if fn(item) {
// 需要排空 s.source,否则前面的goroutine可能阻塞
go drain(s.source)
return true
}
} return false
}

一个也不匹配 NoneMatch

func (s Stream) NoneMatch(fn func(item interface{}) bool) bool {
for item := range s.source {
if fn(item) {
// 需要排空 s.source,否则前面的goroutine可能阻塞
go drain(s.source)
return false
}
} return true
}

数量统计 Count

func (s Stream) Count() int {
var count int
for range s.source {
count++
}
return count
}

清空 Done

func (s Stream) Done() {
// 排空 channel,防止 goroutine 阻塞泄露
drain(s.source)
}

迭代全部元素 ForAll

func (s Stream) ForAll(fn ForAllFunc) {
fn(s.source)
}

迭代每个元素 ForEach

func (s Stream) ForAll(fn ForAllFunc) {
fn(s.source)
}

小结

至此 Stream 组件就全部实现完了,核心逻辑是利用 channel 当做管道,数据当做水流,不断的用协程接收/写入数据到 channel 中达到异步非阻塞的效果。

回到开篇提到的问题,未动手前想要实现一个 stream 难度似乎非常大,很难想象在 go 中 300 多行的代码就能实现如此强大的组件。

实现高效的基础来源三个语言特性:

  • channel
  • 协程
  • 函数式编程

参考资料

pipeline模式

切片反转算法

项目地址

https://github.com/zeromicro/go-zero

欢迎使用 go-zerostar 支持我们!

微信交流群

关注『微服务实践』公众号并点击 交流群 获取社区群二维码。

Go 通过 Map/Filter/ForEach 等流式 API 高效处理数据的更多相关文章

  1. Java8 流式 API(`java.util.stream`)

    熟悉 ES6 的开发者,肯定对数组的一些方法不是很陌生:map.filter 等.在对一组对象进行统一操作时,利用这些方法写出来的代码比常规的迭代代码更加的简练.在 C♯ 中,有 LINQ 来实现.那 ...

  2. jackson 流式API

    http://www.cnblogs.com/lee0oo0/articles/2652528.html Jackson提供了三种可选的JSON处理方法 1.流式API     com.fasterx ...

  3. 流式数据处理在百度数据工厂的应用与实践 原创: 李俊卿 AI前线 今天

    流式数据处理在百度数据工厂的应用与实践 原创: 李俊卿 AI前线 今天

  4. Hadoop_11_HDFS的流式 API 操作

    对于MapReduce等框架来说,需要有一套更底层的API来获取某个指定文件中的一部分数据,而不是一整个文件 因此使用流的方式来操作 HDFS上的文件,可以实现读取指定偏移量范围的数据 1.客户端测试 ...

  5. python3 map,filter和列表推导式

    num_list = [11,2,-33,10,7,3,5,43] 1.filter  函数 获取num_list大于5的元素,并返回列表 用lambda表达式实现: # 在python2 中 fil ...

  6. Jackson流式API

    public class JacksonTester {   public static void main(String args[]){    JacksonTester tester = new ...

  7. lambda表达式以及stream流式api用法

    https://www.cnblogs.com/aoeiuv/p/5911692.html 这篇文章讲的简单全面,记录下 kotlin一些符号的用法 https://www.cnblogs.com/l ...

  8. 搜索广告与广告网络Demand技术-流式计算平台

    流式计算平台-Storm 我们以Storm为例来看流式计算的功能是什么. 下面内容引用自大圆的博客.在Storm中,一个实时应用的计算任务被打包作为Topology发布,这同Hadoop的MapRed ...

  9. Apache Beam—透视Google统一流式计算的野心

    Google是最早实践大数据的公司,目前大数据繁荣的生态很大一部分都要归功于Google最早的几篇论文,这几篇论文早就了以Hadoop为开端的整个开源大数据生态,但是很可惜的是Google内部的这些系 ...

随机推荐

  1. linux修改文件权限命令

    先看个实例: [root@local opt]#ls -al ls -al 命令是列出目录的所有文件,包括隐藏文件.隐藏文件的文件名第一个字符为'.' -rw-r--r--  1 root root  ...

  2. Oracle存储过程游标for循环怎么写

    一.不带参数的游标for循环 首先编写存储过程的整体结构,如下: create or replace procedure test_proc is v_date date; --变量定义 begin ...

  3. jQuery中的html()、text()和val()的用法

    1.html() 获得的是第一个符合要求的标签中的所有内容,例如: var content = $("li").html(); <li>111<p>999& ...

  4. 【C++】最长回文子串/动态规划

    ACM #include <bits/stdc++.h> using namespace std; const int maxn = 1010; char S[maxn]; int dp[ ...

  5. 基于Web的质量和测试度量指标

    直观了解软件质量和测试的完整性 VectorCAST/Analytics可提供便于用户理解的web仪表盘视图来显示软件代码质量和测试完整性指标,让用户能够掌握单个代码库的趋势,或对比多个代码库的度量指 ...

  6. LuoguP7713 「EZEC-10」打分 题解

    Content 某个人去参加比赛,\(n\) 个评委分别给他打分 \(a_1,a_2,\dots,a_n\).这个人可以最多执行 \(m\) 次操作,每次操作将一个评委的分数加 \(1\).定义他的最 ...

  7. 记一次Linux bash 命令行卡顿排查之警惕LD_PRELOAD环境变量

    现象: 通过屏幕或者ssh登录Linux操作系统(本例:Ubuntu)后,执行ls 需要数秒才返回 strace -c ls 查看实际命令调用耗时并不长 对比和正常执行的主机命令执行时,加载的库文件差 ...

  8. 第二周Python笔记 数据类型 列表 字典

    列表,拉锁式儿合并. [ [a,b] for a,b in zip(list1,list2)] #最笨的 a=[1,2,3,4,5] b=[2,3,4,5,6] d=[] for i in range ...

  9. 不同机房vpc使用openswan打通内网

    1.测试环境: 北京6云主机:120.92.51.75/10.0.3.13     VPC:10.0.0.0/16 Ren-test 上海2云主机:42.157.163.120/192.168.3.3 ...

  10. redis启动报错:Fatal error loading the DB: Invalid argument

    redis启动报错 add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be ...