vimでnon-greedyなマッチ
vimでnon-greedyなマッチを行うために正規表現を調べたのでメモ
non-greedyなマッチを使いたい場合のusecase
以下の行でクォーテーション毎にそれぞれマッチしたい場合
'hoge', 'fuga'
アスタリスクを使って書くと行頭から行末まで全体にマッチしてしまう
# greedy /\v'.*' => match "'hoge', 'fuga'" # non-greedy /\v'.{-}' => match "'hoge'" and "'fuga'" separately
{}
は繰り返し回数を指定する場合の正規表現の書き方だが、その頭にハイフンを付けることでnon-greedyという意味になる
例えば{-2,5}
とすれば2~5回の繰り返し(non-greedy)を表せる
ちなみに\v
を置くことでalphabet, number, underscore以外の文字を特殊な意味で使う場合にescapeする必要がなくなる
\Vとすれば逆にすべての文字をescapeなしで文字通りのまま扱える
cf. :h magic
- 作者: Drew Neil,新丈径
- 出版社/メーカー: アスキー・メディアワークス
- 発売日: 2013/08/29
- メディア: 単行本(ソフトカバー)
- この商品を含むブログ (15件) を見る
dynamoDBのpartition分割
dynamoDBはstorage sizeとthroughputが大きくなるにつれてpartitonを増やしていく
その際の挙動について調べたのでメモ
partitionとprimary keyの関係について
Partitions and Data Distribution - Amazon DynamoDB
partition分割時の挙動について
Guidelines for Working with Tables - Amazon DynamoDB
1つのpartitonは
- 10GBのデータを保持できる
- readだけなら3000, writeだけなら1000のcapacityをサポートできる
これを超えるとpartitoinは分割される
あるitemがどのpartitionに含まれるかはhash keyの値をhash関数で処理した値によって決まる
To write an item to the table, DynamoDB uses the value of the partition key as input to an internal hash function. The output value from the hash function determines the partition in which the item will be stored.
Guidelines for Working with Tables - Amazon DynamoDB
のdocumentでも説明されている内容によると、partition分割時にはitemが均等に分割されると図を用いて描かれている
1. Allocate two new partitions (P1 and P2).
2. Distribute the data from P evenly across P1 and P2.
3. Deallocate P from the table.
ただ、hash keyが同一であれば同じpartitionに属するはずなのでhash keyの選び方によっては均等に分割されるとは限らないと考えられる、というか均等になるようにhash keyを選ぶべきということか。
ちなみにGlobal Secondary Indexを用いるときも上記の内容を考慮してhash keyを選ぶ必要がある
Guidelines for Global Secondary Indexes - Amazon DynamoDB
疑問点
例えば以下のようなhask keyがあったとする
- hash key = 1, 2, 3, 4のどれかの値
- 各値ごとに含まれるitem数はそれぞれ1000, 2000, 3000, 4000
この場合、partitionを4つに分けるとすれば一つのpartitionが一つのhash keyを担当する形になるのだと思う。
ではこれを2 partitionに分割する場合は?
- hash keyが(1, 4)と(2, 3)の組み合わせでitem数がそれぞれ5000ずつとなるように分割してくれるのだろうか?
- hash keyを若い方から見ていって半分ずつくらいになるところまでが一つのpartitionとなるのだろうか?
- この例だと(1,2,3)と(4)に分割されるという意味
この辺はparition分割の実装次第になるのだろうが詳細に解説しているdocumentは見つけられなかった。
dynamoDBのitem size計算
dynamoDBのitem sizeを計算する方法を調べたのでメモ
基本式はこれで求まる
属性名のbyte数 + 属性値のbyte数
属性名はstringであり、stringはUTF-8 バイナリエンコードの Unicodeで保持されている
なのでasciiの文字を使っていれば1文字1byte
属性値として使えるデータ型はnumber, string, binary, Boolean, null
Booleanとnull型の場合は常に1byte
それ以外の場合はstringとして数えた場合と同じになる
numberについてはint, doubleなどの型はないため4byte, 8byteなどではなく、
桁数=byte数として計算することができる
example
"Item":{ "name":{"S":"amazon"}, "age":{"N":"20"}, "own_it":{"BOOL":true} }
この場合
name(4) + amazon(6) + age(3) + 20(2) + own_it(6) + true(1)
= 22 bytes