vitesse X use llvm speed up postgresql

Postgres2015全国用户大会将于11月20至21日在北京丽亭华苑酒店召开。本次大会嘉宾阵容强大,国内顶级PostgreSQL数据库专家将悉数到场,并特邀欧洲、俄罗斯、日本、美国等国家和地区的数据库方面专家助阵:

  • Postgres-XC项目的发起人铃木市一(SUZUKI Koichi)
  • Postgres-XL的项目发起人Mason Sharp
  • pgpool的作者石井达夫(Tatsuo Ishii)
  • PG-Strom的作者海外浩平(Kaigai Kohei)
  • Greenplum研发总监姚延栋
  • 周正中(德哥), PostgreSQL中国用户会创始人之一
  • 汪洋,平安科技数据库技术部经理
  • ……
 
  • 2015年度PG大象会报名地址:http://postgres2015.eventdove.com/
  • PostgreSQL中国社区: http://postgres.cn/
  • PostgreSQL专业1群: 3336901(已满)
  • PostgreSQL专业2群: 100910388
  • PostgreSQL专业3群: 150657323



Comparison

Feature Vitesse X Vitesse DB Details
Subscription Pricing $1,000/instance $1,000/core Annual license with email supported included.
Speed1 8X faster 100X faster
(180X faster on column store)
Allow for data exploration with live SQL.
Turn around reports and batch jobs quicker.
Extend HW lifetime and save electricity.
1Speed obtained from TPCH Q1.
100% Postgres Compatibility Deploy and play. No modification necessary on applications, tools or operations.
x86 Acceleration Dynamic query compilation and register-level optimization on modern x86 CPUs.
COPY Operator Acceleration Use fast SSE instructions in COPY instruction to speed up data import.
Parallel Query Execution Employ all available cores to improve productivity of data scientists and data engineers.
Compressible Column Store Reduce I/O on big table scans substantially.

目前vitesse X支持的SQL语句

CREATE TABLE AS SELECT
SELECT

不包含如下

CTE with recursion, although CTE in general are supported.
lead and lag window functions, although other window functions are supported.
Hash, GiST and GIN index, although B-tree is supported.
Functions returning sets.

vitesse X 支持的数据类型

integer, smallint, bigint, boolean 
numeric, real, double precision, money 
text, varchar, enum 
interval, date, timestamp, timestamp with time zone 
json, array

不支持的数据类型

oid, xid, cid, tid
point, box, lseg, line, path, polygon, and circle

不支持的SQL或数据类型,会按照PG原有的模式处理。

安装

# wget http://storage.googleapis.com/vitessedata/download/vitesse_x.9.4.4.rh6.x86_64.bin
# . /home/postgres/.bash_profile 
# which pg_config
/opt/pgsql/bin/pg_config
# bash vitesse_x.9.4.4.rh6.x86_64.bin
so文件达到了16MB
root@digoal-> ll /opt/pgsql/lib/vitesse_x.so 
-rwxr-xr-x 1 root root 16M Sep  6 19:39 /opt/pgsql/lib/vitesse_x.so

root@digoal-> su - postgres
postgres@digoal-> cd $PGDATA
postgres@digoal-> vi postgresql.conf
shared_preload_libraries = 'vitesse_x' 
> pg_ctl restart -m fast

在so文件中看到了几个HOOK,也是通过hook来对执行进行控制的。

root@digoal-> nm -A vitesse_x.so |grep -i hook
vitesse_x.so:                 U ExecutorRun_hook
vitesse_x.so:                 U RunFunctionExecuteHook
vitesse_x.so:0000000000ae1900 T _ZNSt8__detail15_List_node_base7_M_hookEPS0_
vitesse_x.so:0000000000ae1920 T _ZNSt8__detail15_List_node_base9_M_unhookEv
vitesse_x.so:                 U object_access_hook


测试

> psql
postgres=# create extension vitesse_x;
postgres=# select * from pg_settings where name ~ 'vitesse';
        name         |                                      setting                                      | unit |      category      |                                     short_desc                                     | extra_desc | cont
ext  | vartype | source  | min_val |  max_val   | enumvals |                                     boot_val                                      |                                     reset_val                                     | sourcefi
le | sourceline 
---------------------+-----------------------------------------------------------------------------------+------+--------------------+------------------------------------------------------------------------------------+------------+-----
-----+---------+---------+---------+------------+----------+-----------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+---------
---+------------
 vitesse.enable      | on                                                                                |      | Customized Options | Enable use of vitesse engine.                                                      |            | user
     | bool    | default |         |            |          | on                                                                                | on                                                                                |         
   |           
 vitesse.jit_time    | 0                                                                                 |      | Customized Options | Show time in ms consumed by compilation in the last query.                         |            | inte
rnal | integer | default | 0       | 2147483647 |          | 0                                                                                 | 0                                                                                 |         
   |           
 vitesse.last        | 0                                                                                 |      | Customized Options | Show if vitesse engine was used in the last query.                                 |            | inte
rnal | integer | default | 0       | 1          |          | 0                                                                                 | 0                                                                                 |         
   |           
 vitesse.last_reason |                                                                                   |      | Customized Options | Show last error when JIT failed.                                                   |            | inte
rnal | string  | default |         |            |          |                                                                                   |                                                                                   |         
   |           
 vitesse.license     | 20150501|951897|Vitesse X|0|30 DAY LIMITED TRIAL|8c93a440587657eb20a02f02afe7c86a |      | Customized Options | Show license info on vitesse engine.                                               |            | user
     | string  | default |         |            |          | 20150501|951897|Vitesse X|0|30 DAY LIMITED TRIAL|8c93a440587657eb20a02f02afe7c86a | 20150501|951897|Vitesse X|0|30 DAY LIMITED TRIAL|8c93a440587657eb20a02f02afe7c86a |         
   |           
 vitesse.log_level   | 0                                                                                 |      | Customized Options | Log vitesse engine messages: 1 for ERROR, 2 for NOTICE, 3 for INFO, 4 for VERBOSE. |            | user
     | integer | default | 0       | 4          |          | 0                                                                                 | 0                                                                                 |         
   |           
 vitesse.plan_cost   | 12                                                                                |      | Customized Options | Show plan cost estimated by optimizer in the last query.                           |            | inte
rnal | integer | default | 0       | 2147483647 |          | 0                                                                                 | 0                                                                                 |         
   |           
 vitesse.rev         | 607bc87                                                                           |      | Customized Options | Show revision info on vitesse engine.                                              |            | inte
rnal | string  | default |         |            |          | 607bc87                                                                           | 607bc87                                                                           |         
   |           
 vitesse.threshold   | 200                                                                               |      | Customized Options | Engage vitesse engine above this plan cost threshold.                              |            | user
     | integer | default | 0       | 2147483647 |          | 200                                                                               | 200                                                                               |         
   |           
 vitesse.version     | Vitesse Engine for PostgreSQL 9.4.4 [rev 607bc87 on 2015-07-30]                   |      | Customized Options | Show version info on vitesse engine.                                               |            | inte
rnal | string  | default |         |            |          | Vitesse Engine for PostgreSQL 9.4.4 [rev 607bc87 on 2015-07-30]                   | Vitesse Engine for PostgreSQL 9.4.4 [rev 607bc87 on 2015-07-30]                   |         
   |           
(10 rows)

postgres=# \dt+
                   List of relations
 Schema | Name | Type  |  Owner   | Size  | Description 
--------+------+-------+----------+-------+-------------
 public | t    | table | postgres | 40 kB | 
 public | test | table | postgres | 11 MB | 
(2 rows)

postgres=# \d test
     Table "public.test"
 Column |  Type   | Modifiers 
--------+---------+-----------
 id     | integer | not null
 info   | text    | 
Indexes:
    "test_pkey" PRIMARY KEY, btree (id)


postgres=# explain (analyze,verbose,costs,buffers,timing) select count(*), sum(id*id::int8), min(id), max(id), avg(id) from test;
                                                                QUERY PLAN                                                                 
-------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=10000004209.00..10000004209.01 rows=1 width=4) (actual time=32.529..32.529 rows=1 loops=1)
   Output: count(*), sum((id * (id)::bigint)), min(id), max(id), avg(id)
   Buffers: shared hit=1459
   ->  Seq Scan on public.test  (cost=10000000000.00..10000002459.00 rows=100000 width=4) (actual time=32.519..32.519 rows=100000 loops=1)
         Output: id, info
         Buffers: shared hit=1459
 Planning time: 0.121 ms
 Execution time: 40.412 ms
(8 rows)
关闭vitesse插件。
postgres=# set vitesse.enable=off;
SET
postgres=# explain (analyze,verbose,costs,buffers,timing) select count(*), sum(id*id::int8), min(id), max(id), avg(id) from test;
                                                                QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=10000004209.00..10000004209.01 rows=1 width=4) (actual time=96.881..96.881 rows=1 loops=1)
   Output: count(*), sum((id * (id)::bigint)), min(id), max(id), avg(id)
   Buffers: shared hit=1459
   ->  Seq Scan on public.test  (cost=10000000000.00..10000002459.00 rows=100000 width=4) (actual time=0.025..25.734 rows=100000 loops=1)
         Output: id, info
         Buffers: shared hit=1459
 Planning time: 0.120 ms
 Execution time: 96.969 ms
(8 rows)

全缓存命中,性能提升非常明显。
Vitesse DB根据官方的数据,性能提升应该更加明显,LLVM这个方向不错哦。

[参考]
4. 知乎上的llvm简介
LLVM本身并不是编译器,只是一套用于开发编译器、解释器等程序语言相关工具的库,主要聚焦于编译器后端功能,如代码生成、代码优化、JIT等。

所以说“XCode用的编译器是应该是LLVM”是不对的。XCode用的编译器是Clang。Clang是一个基于LLVM开发的C/C++/Obj-C编译器,有一套独立的前端,后端直接采用LLVM。还有一个较为早期的相关项目LLVM-GCC,是一个将GCC的前端嫁接到LLVM之上拼接而成的一个完整的编译器。

Clang自2.8版本起已经可以完整编译Boost了,可以说是Clang成为成熟C++编译器的一个标志。但当时Clang还没有调试器可用,只有一个尚未完成的只支持MacOS平台的LLDB(http://lldb.llvm.org/)。后来不知道是GDB支持了LLVM还是LLVM支持了GDB,总之Clang 3.0的编译产物已经可以用GDB调试了。

苹果之所以资助LLVM,主要原因在于GCC采用GPL协议而LLVM采用BSD协议。另外GCC官方对苹果提出的需求响应不及时,促使苹果急于寻求GCC的替代品。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值