Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1080238
  • 博文数量: 646
  • 博客积分: 288
  • 博客等级: 二等列兵
  • 技术积分: 5375
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-08 14:33
个人简介

为了技术,我不会停下学习的脚步,我相信我还能走二十年。

文章分类

全部博文(646)

文章存档

2014年(8)

2013年(134)

2012年(504)

分类:

2012-07-24 16:24:13

编译和链接怎样影响MySQL的速度

下列大多数测试是在Linux上并用MySQL基准进行的,但是它们能对其它操作系统和工作负载给出一些指示。

当你用-static链接时,可以得到最快的可执行文件。

Linux上,最好用pgcc-O3编译服务器。为了用这些选项编译“sql_yacc.cc”,需要大约200M内存,因为gccpgcc需要大量的内存使所有函数嵌入(inline)。在配置MySQL时,也应该设定CXX=gcc以避免包括libstdc++(它不需要)。请注意对于某些版本的pgcc,生成的二进制只能运行在真Pentium处理器上,即使你使用编译器选项说明你想让最终的代码在所有x586-类处理器上工作(例如AMD)

只通过使用一个较好的编译器或较好的编译器选项,在应用中能得到10-30%的加速。如果你自己编译SQL服务器,这特别重要!

当我们测试Cygnus CodeFusionFujitsu编译器时,二者均还没足够不出错来让MySQL启用优化进行编译。

标准MySQL二进制分发编译为支持所有字符集。当你自己编译MySQL时,应只包括将使用的字符集的支持。通过configure--with-charset选项来控制。

这里是我们做过的一些测量表:

·         如果你使用pgcc并用-O6编译,mysqld服务器比用gcc 2.95.211%

·         如果你动态地链接(没有-static),在Linux中结果慢了13%。注意你仍能在客户应用程序中使用动态链接MySQL库。只有服务器对性能是关键的。

·         如果你用strip mysqld剥离mysqld二进制,生成的二进制可以快4%

·         对于在同一主机上运行的客户与服务器之间的连接,如果你使用TCP/IP而非Unix套接字文件进行连接,结果慢7.5%(Unix中,如果你连接localhost主机,MySQL默认使用一个套接字文件)

·         对于从客户到服务器的TCP/IP连接,从另一台主机连接一台远程服务器要比连接同一主机上的服务器慢8-11%,即使通过100Mb/s以太网进行连接。

·         当使用安全连接运行我们的基准测试时(所有数据用内部SSL支持进行加密),性能比未加密连接慢55%

·         如果你用--with-debug=full编译,大多数查询慢20%。部分查询时间会很长;例如,MySQL基准的运行要慢35%。如果你使用--with-debug(没有=full),速度只下降15%。对于用--with-debug=full编译的mysqld版本,可以用--skip-safemalloc选项启动以便在运行时禁用内存检查。执行速度则接近用--with-debug配置的时候。

·         Sun UltraSPARC-Iie上,用Forte 5.0编译的服务器比用gcc 3.2编译的要快4%

·         Sun UltraSPARC-Iie上,用Forte 5.0编译的32位模式服务器比64位模式服务器要快4%

·         gcc 2.95.2编译带-mcpu=v8 -WaUltraSPARC,使用-xarch=v8plusa选项性能会提高4%

·         Solaris 2.5.1上,在单个处理器上MIT-pthreads比带原生线程的Solaris8-12%。如果有更大的负载/cpus,差别应该更大。

·         Linux-x86上使用gcc编译而不用帧指针(-fomit-frame-pointer or -fomit-frame-pointer -ffixed-ebp),可以使mysqld1-4%

MySQL AB提供的Linux上的二进制MySQL分发一般用pgcc编译。我们必须返回到常规gcc,因为pgcc中有一个bug,使生成的二进制不能在AMD上运行。我们将继续使用gcc直到该bug被解决。同时,如果你有一个非AMD机,你可以用pgcc编译构建一个更快的二进制。标准MySQL Linux二进制是通过静态链接,以使它更快并且更加易于移植。

 

 
[root@mysql1 mysql-5.1.41]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']
Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]
Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]
Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --disable-dependency-tracking  speeds up one-time build
  --enable-dependency-tracking   do not reject slow dependency extractors
  --enable-shared[=PKGS]  build shared libraries [default=yes]
  --enable-static[=PKGS]  build static libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --disable-community-features
                          Disable additional features provided by the user
                          community.
  --disable-thread-safe-client
                          Compile the client without threads.
  --enable-assembler      Use assembler versions of some string
                          functions if available.

  --enable-profiling      Build a version with query profiling code (req.
                          community-features)
  --enable-local-infile   Enable LOAD DATA LOCAL INFILE (default: disabled)
  --disable-grant-options Disables the use of --init-file, --skip-grant-tables and --bootstrap options
  --disable-largefile     Omit support for large files
  --enable-debug-sync     Build a version with Debug Sync Facility
Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
选择字符集
  --with-charset=CHARSET
                          Default character set, use one of:
                          binary
                          armscii8 ascii big5 cp1250 cp1251 cp1256 cp1257
                          cp850 cp852 cp866 cp932 dec8 eucjpms euckr gb2312 gbk geostd8
                          greek hebrew hp8 keybcs2 koi8r koi8u
                          latin1 latin2 latin5 latin7 macce macroman
                          sjis swe7 tis620 ucs2 ujis utf8
  --with-collation=COLLATION
                          Default collation

  --with-extra-charsets=CHARSET,CHARSET,...
                          Use charsets in addition to default (none, complex,
                          all, or a list selected from the above sets)
  --without-uca           Skip building of the national Unicode collations.
  --with-system-type      Set the system type, like "sun-solaris10"
  --with-machine-type     Set the machine type, like "powerpc"
  --with-darwin-mwcc      Use Metrowerks CodeWarrior wrappers on OS X/Darwin
  --with-pic              try to use only PIC/non-PIC objects [default=use
                          both]
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-other-libc=DIR   Link against libc and other standard libraries
                          installed in the specified non-standard location
                          overriding default. Originally added to be able to
                          link against glibc 2.2 without making the user
                          upgrade the standard libc installation.
  --with-server-suffix    Append value to the version string.
  --with-pthread          Force use of pthread library.
  --with-named-thread-libs=ARG
                          Use specified thread libraries instead of
                          those automatically found by configure.
  --with-named-curses-libs=ARG
                          Use specified curses libraries instead of
                          those automatically found by configure.
本地连接使用unix套接字
  --with-unix-socket-path=SOCKET
                          Where to put the unix-domain socket.  SOCKET must be
                          an absolute file name.
远程tcp连接使用的端口号(多实例启动时常用)
  --with-tcp-port=port-number
                          Which port to use for MySQL services (default 3306)

  --with-mysqld-user=username
                          What user the mysqld daemon shall be run as.
  --with-zlib-dir=no|bundled|DIR
                          Provide MySQL with a custom location of compression
                          library. Given DIR, zlib binary is assumed to be in
                          $DIR/lib and header files in $DIR/include.
  --with-libwrap=DIR      Compile in libwrap (tcp_wrappers) support
  --with-pstack           Use the pstack backtrace library
  --with-debug            Add debug code
  --with-debug=full       Add debug code (adds memory checker, very slow)
  --with-error-inject     Enable error injection in MySQL Server
- 与快速,互斥与(默认快速互斥编译被禁用)
  --with-fast-mutexes     Compile with fast mutexes (default is disabled)
  --with-atomic-ops=rwlocks|smp|up
                          Implement atomic operations using pthread rwlocks or
                          atomic CPU instructions for multi-processor
                          (default) or uniprocessor configuration
选择静态编译
  --with-mysqld-ldflags   Extra linking arguments for mysqld
  --with-client-ldflags   Extra linking arguments for clients
  --with-mysqld-libs   Extra libraries to link with for mysqld
  --with-lib-ccflags      Extra CC options for libraries
  --with-low-memory       Try to use less memory to compile to avoid
                          memory limitations.
  --with-comment          Comment about compilation environment.
支持超大表
  --with-big-tables       Support tables with more than 4 G rows even on 32
                          bit platforms

  --with-max-indexes=N    Sets the maximum number of indexes per table,
                          default 64
  --with-ssl=DIR    Include SSL support
选择功能插件和引擎插件
  --with-plugins=PLUGIN[[[,PLUGIN..]]]
                          Plugins to include in mysqld. (default is: none)
                          Must be a configuration name or a comma separated
                          list of plugins.
                          Available configurations are: none max max-no-ndb
                          all.
                          Available plugins are:
partition daemon_example
                          ftexample archive blackhole csv example federated
                          heap ibmdb2i innobase innodb_plugin myisam myisammrg
                          ndbcluster.
  --without-plugin-PLUGIN Disable the named plugin from being built.
                          Otherwise, for plugins which are not selected for
                          inclusion in mysqld will be built dynamically (if
                          supported)
  --with-plugin-PLUGIN    Forces the named plugin to be linked into mysqld
                          statically.
  --with-ndb-sci=DIR      Provide MySQL with a custom location of sci library.
                          Given DIR, sci library is assumed to be in $DIR/lib
                          and header files in $DIR/include.
  --with-ndb-test       Include the NDB Cluster ndbapi test programs
  --with-ndb-docs       Include the NDB Cluster ndbapi and mgmapi documentation
  --with-ndb-port       Port for NDB Cluster management server
  --with-ndb-port-base  Base port for NDB Cluster transporters
  --without-ndb-debug   Disable special ndb debug features
  --with-ndb-ccflags=CFLAGS
                          Extra CFLAGS for ndb compile
  --without-ndb-binlog       Disable ndb binlog
仅安装客户端
  --without-server        Only build the client.
  --with-embedded-server  Build the embedded server (libmysqld).
  --without-query-cache   Do not build query cache.
  --without-geometry      Do not build geometry-related parts.
  --with-embedded-privilege-control
                          Build parts to check user's privileges.
     Only affects embedded library.
  --with-mysqlmanager     Build the mysqlmanager binary: yes/no (default:
                          build if server is built.)
  --without-docs          Skip building of the documentation.
  --without-man          Skip building of the man pages.
  --without-readline      Use system readline instead of bundled copy.
  --without-libedit       Use system libedit instead of bundled copy.
Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L if you have libraries in a
              nonstandard directory
  LIBS        libraries to pass to the linker, e.g. -l
  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I if
              you have headers in a nonstandard directory
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  CPP         C preprocessor
  CXXCPP      C++ preprocessor
  CCAS        assembler compiler command (defaults to CC)
  CCASFLAGS   assembler compiler flags (defaults to CFLAGS)
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
请关注Supports build,有些插件是不支持静态编译的需要在性能和功能之间取舍
Description of plugins:
   === Partition Support ===
  Plugin Name:      partition
  Description:      MySQL Partitioning Support
  Supports build:   static
  Configurations:   max, max-no-ndb
   === Daemon Example Plugin ===
  Plugin Name:      daemon_example
  Description:      This is an example plugin daemon.
  Supports build:   dynamic
   === Simple Parser ===
  Plugin Name:      ftexample
  Description:      Simple full-text parser plugin
  Supports build:   dynamic
   === Archive Storage Engine ===
  Plugin Name:      archive
  Description:      Archive Storage Engine
  Supports build:   static and dynamic
  Configurations:   max, max-no-ndb
   === Blackhole Storage Engine ===
  Plugin Name:      blackhole
  Description:      Basic Write-only Read-never tables
  Supports build:   static and dynamic
  Configurations:   max, max-no-ndb
   === CSV Storage Engine ===
  Plugin Name:      csv
  Description:      Stores tables in text CSV format
  Supports build:   static
  Status:           mandatory 强制安装
   === Example Storage Engine ===
  Plugin Name:      example
  Description:      Example for Storage Engines for developers
  Supports build:   dynamic
  Configurations:   max, max-no-ndb
   === Federated Storage Engine ===
  Plugin Name:      federated
  Description:      Connects to tables on remote MySQL servers
  Supports build:   static and dynamic
  Configurations:   max, max-no-ndb
   === Memory Storage Engine ===
  Plugin Name:      heap
  Description:      Volatile memory based tables
  Supports build:   static
  Status:           mandatory
   === IBM DB2 for i Storage Engine ===
  Plugin Name:      ibmdb2i
  Description:      IBM DB2 for i Storage Engine
  Supports build:   dynamic
  Configurations:   max, max-no-ndb
   === InnoDB Storage Engine ===
  Plugin Name:      innobase
  Description:      Transactional Tables using InnoDB
  Supports build:   static and dynamic
  Configurations:   max, max-no-ndb
   === InnoDB Storage Engine ===
  Plugin Name:      innodb_plugin
  Description:      Transactional Tables using InnoDB
  Supports build:   dynamic
  Configurations:   max, max-no-ndb
   === MyISAM Storage Engine ===
  Plugin Name:      myisam
  Description:      Traditional non-transactional MySQL tables
  Supports build:   static
  Status:           mandatory
   === MyISAM MERGE Engine ===
  Plugin Name:      myisammrg
  Description:      Merge multiple MySQL tables into one
  Supports build:   static
  Status:           mandatory
   === Cluster Storage Engine ===
  Plugin Name:      ndbcluster
  Description:      High Availability Clustered tables
  Supports build:   static
  Configurations:   max
阅读(484) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~