Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cloudflare Workersのデータストア、KVとD1を比較してみる / Cloudflare Workers datastore, comparing KV and D1.

Cloudflare Workersのデータストア、KVとD1を比較してみる / Cloudflare Workers datastore, comparing KV and D1.

Cloudflare Meetup Oita Kick off!!
https://cfm-cts.connpass.com/event/285212/

shiro seike

July 22, 2023
Tweet

More Decks by shiro seike

Other Decks in Programming

Transcript

  1. Cloudflare Workers

    KV D
    1
    Cloudflare Meetup Oita Kick off!!
    2
    0
    23
    .
    07
    .
    22



    @seike
    4
    60
    1

    View full-size slide

  2. @seike
    460
    -


    - @seike
    46
    0

    - Fusic


    - /


    - /

    -


    - Cloudflare Meet-up Fukuoka Organizer


    - ServerlessDays
    20
    23
    Organizer


    - JAWS Festa
    2023
    Staff
    2

    View full-size slide

  3. Agenda
    1
    .Cloudflare Workers


    2
    .Cloudflare Workers KV


    3
    .Cloudflare D
    1


    4
    .Workers KV D
    1

    5
    .Workers KV D
    1
    3

    View full-size slide

  4. 01
    Cloudflare Workers

    View full-size slide

  5. Cloudflare Workers
    Workers Cloudflare




    Web

    Workers Cloudflare Developer Platform



    5

    View full-size slide

  6. 02
    Cloudflare Workers KV

    View full-size slide

  7. Cloudflare Workers KV
    Key-Value

    275 Key-Value
    
 



    7

    View full-size slide

  8. 03
    Cloudflare Workers KV

    View full-size slide

  9. Cloudflare Workers D
    1
    D
    1
    Cloudflare


    D
    1
    SQLite


    SQL

    Web
    9

    View full-size slide

  10. 04
    Workers KV D
    1

    View full-size slide

  11. 11
    GA I/F
    Wokers 1 10 JS
    -
    KV 1 10


    1 1,000

    Key-Value
    ?
    D
    1
    Read units
    5
    million / day


    Write units
    100
    ,
    00 0
    / day
    SQL
    ?
    10 KV 1000 ? ?


    ?

    View full-size slide

  12. 05
    Workers KV D
    1

    View full-size slide

  13. KV
    14
    export const getPresentationsKV = async (KV: KVNamespace):
    Promise => {


    const startTimePut = performance.now();


    for (let i = 0; i < 100; i++) {


    await KV.put(i.toString(), i.toString());


    }


    const endTimePut = performance.now();


    let putTime = endTimePut - startTimePut;


    for (let i = 0; i < 100; i++) {


    const value = await KV.get(i.toString());


    }


    const endTimeGet = performance.now();


    const getTime = endTimeGet - endTimePut;


    return 'putTime: ' + putTime + ' - getTime: ' + getTime;


    };

    View full-size slide

  14. D
    1
    15
    export const getPresentation = async (DB: D1Database, id: string):
    Promise => {


    await DB.prepare('DELETE FROM Presentations').run();


    const startTimePut = performance.now();


    for (let i = 0; i < 100; i++) {


    await DB.prepare('INSERT INTO Presentations (id) VALUES (?)’)


    .bind(i.toString()).run();


    }


    const endTimePut = performance.now();


    let putTime = endTimePut - startTimePut;


    for (let i = 0; i < 100; i++) {


    const value = await DB.prepare('SELECT id FROM Presentations WHERE id = ?')


    .bind(i.toString())


    .first();


    }


    const endTimeGet = performance.now();


    const getTime = endTimeGet - endTimePut;


    const newPresentation: Presentation = {


    name: 'putTime: ' + putTime + ' - getTime: ' + getTime,


    };


    return newPresentation;


    };

    View full-size slide

  15. KV Insert


    putTime ---------


    2
    34
    2 6

    getTime ---------


    1
    22
    2

    KV Update


    putTime ---------


    2
    37
    6 3

    getTime ---------


    1
    25
    4

    D
    1

    putTime ---------


    1
    98
    3 2

    getTime ---------


    1
    53
    8 5
    16

    View full-size slide

  16. Point
    KV


    D
    1

    D
    1
    β

    View full-size slide

  17. Serverless Days Tokyo
    2023
    18

    View full-size slide

  18. Thank You
    We are Hiring !


    https://recruit.fusic.co.jp/

    View full-size slide