Hot and cold data sources

참치돌고래·2022년 12월 13일
0

Hot

  • Collections(List, Set)
  • Channel

Cold

  • Sequence, Stream
  • Flow, RxJava, streams
{
    val l = buildList {
        repeat(3) {
            add("User$it")
            println("L : Added User")
        }
    }

    val l2 = l.map{
        println("L : Processing")
        "Processed $it"
    }

    val s = sequence {
        repeat(3) {
            yield("User$it")
            println("S : Added User")
        }
    }

    val s2 = s.map{
        println("S : Procssing")
        "Processed $it"
    }
}

output

L : Added User
L : Added User
L : Added User
L : Processing
L : Processing
L : Processing

cold data는 즉각적으로 데이터를 소비하지않고 hot 보다 lazy한 특성을 가지고 있다는 것을 볼 수 있다.

Hot channels, cold flow

val channel = produce {
	while (true) { 
    	val x = computeNextValue()
        send(x)
    }
}

val flow = flow {
	while (true) {
    	val x = computeNextValue()
        emit(x)
    }
}

produce메소드는 즉각적으로 데이터를 channel로 전송할 것이다. 하지만 flow의 경우에는 consumer가 존재하는 경우에 data를 생성하기 시작할 것이다.
Hot data = eager

  • 즉시 생성하고, 데이터를 저장한다.
  • consumer와 독립적인 관계를 가지고 데이터를 생성한다.
  • List, Set, Channel ...

Cold data = lazy

profile
안녕하세요

0개의 댓글