9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

続・Redshiftを試してみる

Posted at

前回に引き続きredshiftを試したメモです。

1000万行のデータのImportやSelectなど

以下のようなデータをImportしてみます。
前回との違いは、response フィールドに多少大きめのデータを格納して、1レコード当たりのサイズが大きいことです。

  • type: varchar(32)
  • point: int
  • response: varchar(65535) # 65535 が MAX
  • event_datetime: datetime

DDLは以下のようにしました。

Create Table sample2 (
  type VARCHAR(32) ENCODE TEXT255,
  point INT,
  response VARCHAR(65535),
  event_datetime TIMESTAMP
)
DISTSTYLE EVEN
SORTKEY (event_datetime);

Importするデータを適当に作ります

make_data2.rb
# coding: utf-8

num = ARGV.shift.to_i
DELI = "\001"

TYPES = ["cat", "dog", "cow", "horse"]

num.times do |i|
  type = TYPES[i % TYPES.size]
  point = Random.rand(10) + 1
  response = (Random.rand(63)+33).chr * (Random.rand(2000) + 800)
  dt = Time.now.utc
  puts [type, point, response, dt].join(DELI)
end

1万行のデータを1000個作ってS3にUploadする

for i in {000..999};do; ruby make_data2.rb 10000 | gzip > files/sample2.data.${i}.gz;done 
s3cmd put files/sample2.data.* s3://BUCKET/redshift/sample2/   

Fileサイズは合計79MB程(gzip後)。

Import や Select の実行時間

※ちなみにQueryの実行時間はRedshiftのWeb管理コンソールのQueriesタブから確認できます。

COPY sample2
FROM 's3://BUCKET/redshift/sample2/sample2.data'
GZIP
DELIMITER '\001'
CREDENTIALS 'aws_access_key_id=****;aws_secret_access_key=****'
;
 520

mydb=# select count(*) from sample2;
  count   
----------
 10000000
(1 )
 2.34

mydb=# select type, count(*) from sample2 group by type;
 type  |  count  
-------+---------
 dog   | 2500000
 cat   | 2500000
 cow   | 2500000
 horse | 2500000
(4 )
 5.54

DISK使用量

Performanceタブで確認すると、「Percentage of Disk Space Used」0.83% になっていました。

2TB × 0.0083 ≒ 16GB

です。

今回の1レコード当たり約2000B弱かな、という感じなので、

2000B × 1千万レコード(10Mレコード) -> 20GB

となり、説明がつきそうなサイズになっています。

Import速度とファイルサイズや数の関係?

先ほどのファイルは1つ当たり79KBと小さめだったのでまとめた方がImportにかかる実行時間が短くなるかなと思ってもう一度検証。今度は、100万行を10個で試してみる(1ファイル当たり約7.9MB)。

for i in {0..9};do; gzip -dc files/sample2.data.${i}* | gzip > files2/sample2b.data.${i}.gz; done
s3cmd put files2/sample2b.data.* s3://BUCKET/redshift/sample2b/   
COPY sample2
FROM 's3://BUCKET/redshift/sample2b/sample2b.data'
GZIP
DELIMITER '\001'
CREDENTIALS 'aws_access_key_id=***********;aws_secret_access_key=***********'
;
-> 458

この時は62秒程短かくなりました(でも、もう一度実行したら遅かったので誤差の範囲のようです)。

Selectの速度は変わったかな?

mydb=# select type, count(*) from sample2 group by type;
 type  |  count  
-------+---------
 dog   | 5000000
 cat   | 5000000
 cow   | 5000000
 horse | 5000000
(4 )
-> 1.62

この程度では影響ないようです。

  • もう一度、1万行×1000ファイルをImportしてみる。

    • → 474秒 (先程は520秒)
  • もう一度、100万行×10FileをImportしてみる。

    • → 521秒 (先程は458秒)
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?