DragonflyBSD + Redis インストールログ

単純に pkg で redis インストールするだけ.

環境

  • DragonFly v4.0.1.2.gf72e0-RELEASE

ログ

$ sudo pkg install redis
Updating Avalon repository catalogue...
Avalon repository is up-to-date.
All repositories are up-to-date.
The following 1 packages will be affected (of 0 checked): 
 
New packages to be INSTALLED:
        redis: 2.8.19

The process will require 2 MB more space.
328 KB to be downloaded.

Proceed with this action? [y/N]: y
Fetching redis-2.8.19.txz: 100%  328 KB  84.1k/s    00:04    
Checking integrity... done (0 conflicting)
[1/1] Installing redis-2.8.19...
===> Creating users and/or groups.
Creating group 'redis' with gid '535'.
Creating user 'redis' with uid '535'.
[1/1] Extracting redis-2.8.19: 100%
Message for redis-2.8.19:
 ===>  CONFIGURATION NOTE:

      To setup "redis" you need to edit the configuration file:
      /usr/local/etc/redis.conf

      To run redis from startup, add redis_enable="YES"
      in your /etc/rc.conf.

OS 起動時に起動するようにする

$ sudo sh -c 'echo "redis_enable=\"YES\"" >> /etc/rc.conf'

なんか デフォルトで bind コメントアウトされてるのでつける.

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
bind 127.0.0.1

起動

$ sudo service redis start

DragonflyBSD + HHVM インストール失敗ログ

参考

Building and Installing on FreeBSD 8.2 · facebook/hhvm Wiki · GitHub

環境

  • DragonFly v4.0.1.2.gf72e0-RELEASE

ログ

とりあえずソース取ってくる

$ git clone git://github.com/facebook/hhvm.git --depth=1

Cloning into 'hhvm'...
remote: Counting objects: 43045, done.
remote: Compressing objects: 100% (33026/33026), done.
remote: Total 43045 (delta 6641), reused 30989 (delta 5602)
Receiving objects: 100% (43045/43045), 22.17 MiB | 2.39 MiB/s, done.
Resolving deltas: 100% (6641/6641), done.
Checking connectivity... done.
Checking out files: 100% (56082/56082), done.

サブモジュール取得

$ cd hhvm
$ git submodule update --init --recursive
Submodule 'third-party' (https://github.com/hhvm/hhvm-third-party.git) registered for path 'third-party'
Cloning into 'third-party'...
remote: Counting objects: 2471, done.
remote: Total 2471 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2471/2471), 6.88 MiB | 1.35 MiB/s, done.
Resolving deltas: 100% (1270/1270), done.
Checking connectivity... done.
Submodule path 'third-party': checked out 'd0cad57b5427f84af8f77d60b8b53de4aaea4694'
Submodule 'folly' (https://github.com/facebook/folly.git) registered for path 'folly/src'
Submodule 'proxygen/src' (https://github.com/facebook/proxygen) registered for path 'proxygen/src'
Submodule 'thrift/src' (https://github.com/facebook/fbthrift.git) registered for path 'thrift/src'
Cloning into 'folly/src'...
remote: Counting objects: 9977, done.
remote: Total 9977 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (9977/9977), 4.38 MiB | 852.00 KiB/s, done.
Resolving deltas: 100% (7660/7660), done.
Checking connectivity... done.
Submodule path 'third-party/folly/src': checked out '6f9b619d9ffc219296a818a83266d60628e6aedd'
Cloning into 'proxygen/src'...
remote: Counting objects: 2265, done.
remote: Total 2265 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2265/2265), 860.75 KiB | 191.00 KiB/s, done.
Resolving deltas: 100% (1684/1684), done.
Checking connectivity... done.
Submodule path 'third-party/proxygen/src': checked out '8a602aa40383d6dddbdcb2a951067b9923edfc74'
Cloning into 'thrift/src'...
remote: Counting objects: 10698, done.
remote: Total 10698 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (10698/10698), 5.76 MiB | 989.00 KiB/s, done.
Resolving deltas: 100% (7956/7956), done.
Checking connectivity... done.
Submodule path 'third-party/thrift/src': checked out 'bba5d4590ff71e8f34ce4f90a8d7b2cf867ca3d0'

とりあえず cmake 叩いてみる.

$ cmake .
— The C compiler identification is GNU 4.7.4
— The CXX compiler identification is GNU 4.7.4
— The ASM compiler identification is GNU
— Found assembler: /usr/bin/cc
— Check for working C compiler: /usr/bin/cc
— Check for working C compiler: /usr/bin/cc — works
— Detecting C compiler ABI info
— Detecting C compiler ABI info – done
— Check for working CXX compiler: /usr/bin/CC
— Check for working CXX compiler: /usr/bin/CC — works
— Detecting CXX compiler ABI info
— Detecting CXX compiler ABI info – done
— Performing Test IS_AARCH64
— Performing Test IS_AARCH64 – Failed
— Build type not specified: cmake build type Release.
CMake Error at CMake/HPHPCompiler.cmake:50 (message):
hhvm requires g++ 4.8 or greater.
Call Stack (most recent call first):
CMake/HPHPSetup.cmake:95 (include)
third-party/CMakeLists.txt:18 (include)

gcc が 4.8 以上じゃないと行けないらしいのでとりあえず gcc49 入れてみる.

$ sudo pkg install gcc49      
Updating Avalon repository catalogue...
Avalon repository is up-to-date.
All repositories are up-to-date.
The following 5 packages will be affected (of 0 checked):

New packages to be INSTALLED:
        gcc49: 4.9.3.s20150114
        mpfr: 3.1.2_2
        gmp: 5.1.3_2
        mpc: 1.0.2_1
        binutils: 2.25

The process will require 191 MB more space.
38 MB to be downloaded.

Proceed with this action? [y/N]: y
Fetching gcc49-4.9.3.s20150114.txz: 100%   33 MB 259.2k/s    02:13    
Fetching mpfr-3.1.2_2.txz: 100%  346 KB  70.8k/s    00:05    
Fetching gmp-5.1.3_2.txz: 100%  447 KB  91.5k/s    00:05    
Fetching mpc-1.0.2_1.txz: 100%   75 KB  77.2k/s    00:01    
Fetching binutils-2.25.txz: 100%    4 MB 409.4k/s    00:11    
Checking integrity... done (0 conflicting)
[1/5] Installing gmp-5.1.3_2...
[1/5] Extracting gmp-5.1.3_2: 100%
[2/5] Installing mpfr-3.1.2_2...
[2/5] Extracting mpfr-3.1.2_2: 100%
[3/5] Installing mpc-1.0.2_1...
[3/5] Extracting mpc-1.0.2_1: 100%
[4/5] Installing binutils-2.25...
[4/5] Extracting binutils-2.25: 100%
[5/5] Installing gcc49-4.9.3.s20150114...
[5/5] Extracting gcc49-4.9.3.s20150114: 100%
Message for gcc49-4.9.3.s20150114:
 To ensure binaries built with this toolchain find appropriate versions
of the necessary run-time libraries, you may want to link using

  -Wl,-rpath=/usr/local/lib/gcc49

For ports leveraging USE_GCC, USES=compiler, or USES=fortran this happens
transparently.

もっかい挑戦するも同じく g++ が 4.7.4 だと言い続ける. 調べてみるとどうも /usr/bin/CC を叩いてるようだけどこれが 4.7.4 らしい.

$ /usr/bin/CC -dumpversion
4.7.4

gcc49 は別にあるのでこいつを使うように暫定で変更してみる.

$ which gcc49
/usr/local/bin/gcc49
$ sudo mv /usr/bin/CC /usr/bin/CC.old
$ sudo ln -s /usr/local/bin/gcc49 /usr/bin/CC

ビルド

$ cmake .
-- Build type not specified: cmake build type Release.
-- Found LibDL: /usr/lib/libdl.so  
-- Performing Test LIBDL_NEEDS_UNDERSCORE
-- Performing Test LIBDL_NEEDS_UNDERSCORE - Failed
CMake Error at /usr/local/share/cmake/Modules/FindBoost.cmake:1182 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  CMake/HPHPFindLibs.cmake:31 (find_package)
  CMake/HPHPSetup.cmake:97 (include)
  third-party/CMakeLists.txt:18 (include)


-- Could NOT find LIBGLOG (missing:  LIBGLOG_LIBRARY LIBGLOG_INCLUDE_DIR) 
-- Could NOT find LIBINOTIFY (missing:  LIBINOTIFY_LIBRARY LIBINOTIFY_INCLUDE_DIR) 
-- Found LIBICONV: /usr/local/lib/libiconv.so  
-- Performing Test LIBICONV_CONST
-- Performing Test LIBICONV_CONST - Failed
-- MySQL Include dir: /usr/local/include/mysql  library dir: /usr/local/lib/mysql
-- MySQL client libraries: mysqlclient_r
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
-- Could NOT find LIBMEMCACHED (missing:  LIBMEMCACHED_LIBRARY LIBMEMCACHED_INCLUDE_DIR) 
CMake Error at CMake/HPHPFindLibs.cmake:76 (message):
  libmemcache is too old, found 0 and we need 0.39
Call Stack (most recent call first):
  CMake/HPHPSetup.cmake:97 (include)
  third-party/CMakeLists.txt:18 (include)

libmemcache が古い.ていうか入ってなくね?

$ sudo pkg install libmemcached
Updating Avalon repository catalogue...
Avalon repository is up-to-date.
All repositories are up-to-date.
The following 3 packages will be affected (of 0 checked):

New packages to be INSTALLED:
        libmemcached: 1.0.18
        cyrus-sasl: 2.1.26_9
        libevent2: 2.0.22

The process will require 9 MB more space.
1 MB to be downloaded.

Proceed with this action? [y/N]: y
Fetching libmemcached-1.0.18.txz: 100%  736 KB 107.7k/s    00:07    
Fetching cyrus-sasl-2.1.26_9.txz: 100%  467 KB  95.6k/s    00:05    
Fetching libevent2-2.0.22.txz: 100%  274 KB  93.6k/s    00:03    
Checking integrity... done (0 conflicting)
[1/3] Installing cyrus-sasl-2.1.26_9...
*** Added group `cyrus' (id 60)
*** Added user `cyrus' (id 60)
[1/3] Extracting cyrus-sasl-2.1.26_9: 100%
[2/3] Installing libevent2-2.0.22...
[2/3] Extracting libevent2-2.0.22: 100%
[3/3] Installing libmemcached-1.0.18...
[3/3] Extracting libmemcached-1.0.18: 100%
Message for cyrus-sasl-2.1.26_9:
 You can use sasldb2 for authentication, to add users use:

        saslpasswd2 -c username

If you want to enable SMTP AUTH with the system Sendmail, read
Sendmail.README

NOTE: This port has been compiled with a default pwcheck_method of
      auxprop.  If you want to authenticate your user by /etc/passwd,
      PAM or LDAP, install ports/security/cyrus-sasl2-saslauthd and
      set sasl_pwcheck_method to saslauthd after installing the
      Cyrus-IMAPd 2.X port.  You should also check the
      /usr/local/lib/sasl2/*.conf files for the correct
      pwcheck_method.
      If you want to use GSSAPI mechanism, install
      ports/security/cyrus-sasl2-gssapi.
      If you want to use LDAP auxprop plugin, install
      ports/security/cyrus-sasl2-ldapdb.

ビルド

$ $ cmake .                                    
-- Build type not specified: cmake build type Release.
CMake Error at /usr/local/share/cmake/Modules/FindBoost.cmake:1182 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  CMake/HPHPFindLibs.cmake:31 (find_package)
  CMake/HPHPSetup.cmake:97 (include)
  third-party/CMakeLists.txt:18 (include)


-- Could NOT find LIBGLOG (missing:  LIBGLOG_LIBRARY LIBGLOG_INCLUDE_DIR) 
-- Could NOT find LIBINOTIFY (missing:  LIBINOTIFY_LIBRARY LIBINOTIFY_INCLUDE_DIR) 
-- MySQL Include dir: /usr/local/include/mysql  library dir: /usr/local/lib/mysql
-- MySQL client libraries: mysqlclient_r
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
-- Found LIBMEMCACHED: /usr/local/lib/libmemcached.so  
-- Found PCRE: /usr/local/lib/libpcre.so  
-- Performing Test SYSTEM_PCRE_HAS_JIT
-- Performing Test SYSTEM_PCRE_HAS_JIT - Failed
-- System PCRE does not have JIT enabled - will use hhvm-third-party/pcre
-- Found libevent: /usr/local/lib/libevent.so
-- Looking for evhttp_bind_socket_with_fd
-- Looking for evhttp_bind_socket_with_fd - not found
-- Could NOT find LibUODBC (missing:  LIBODBC_LIBRARIES LIBODBC_INCLUDE_DIRS) 
-- Found CURL: /usr/local/lib/libcurl.so (found version "7.39.0") 
-- Looking for curl_multi_select
-- Looking for curl_multi_select - not found
-- Looking for curl_multi_wait
-- Looking for curl_multi_wait - found
-- Found LibXml2: /usr/local/lib/libxml2.so (found version "2.9.2") 
CMake Error at /usr/local/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
  Could NOT find LibXslt (missing: LIBXSLT_LIBRARIES LIBXSLT_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/local/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:374 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake/Modules/FindLibXslt.cmake:79 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMake/HPHPFindLibs.cmake:130 (find_package)
  CMake/HPHPSetup.cmake:97 (include)
  third-party/CMakeLists.txt:18 (include)

libxslt が足りない

$ sudo pkg install libxslt     
Updating Avalon repository catalogue...
Avalon repository is up-to-date.
All repositories are up-to-date.
The following 3 packages will be affected (of 0 checked):

New packages to be INSTALLED:
        libxslt: 1.1.28_6
        libgcrypt: 1.6.2
        libgpg-error: 1.17

The process will require 3 MB more space.
787 KB to be downloaded.

Proceed with this action? [y/N]: y
Fetching libxslt-1.1.28_6.txz: 100%  227 KB  77.4k/s    00:03    
Fetching libgcrypt-1.6.2.txz: 100%  447 KB  91.6k/s    00:05    
Fetching libgpg-error-1.17.txz: 100%  113 KB  57.8k/s    00:02    
Checking integrity... done (0 conflicting)
[1/3] Installing libgpg-error-1.17...
[1/3] Extracting libgpg-error-1.17: 100%
[2/3] Installing libgcrypt-1.6.2...
[2/3] Extracting libgcrypt-1.6.2: 100%
[3/3] Installing libxslt-1.1.28_6...
[3/3] Extracting libxslt-1.1.28_6: 100%

ビルド

$ cmake .
-- Could NOT find LIBGLOG (missing:  LIBGLOG_LIBRARY LIBGLOG_INCLUDE_DIR) 
-- Could NOT find LIBINOTIFY (missing:  LIBINOTIFY_LIBRARY LIBINOTIFY_INCLUDE_DIR) 
-- MySQL Include dir: /usr/local/include/mysql  library dir: /usr/local/lib/mysql
-- MySQL client libraries: mysqlclient_r
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
-- System PCRE does not have JIT enabled - will use hhvm-third-party/pcre
-- Found libevent: /usr/local/lib/libevent.so
-- Could NOT find LibUODBC (missing:  LIBODBC_LIBRARIES LIBODBC_INCLUDE_DIRS) 
-- Found LibXslt: /usr/local/lib/libxslt.so (found version "1.1.28") 
-- Found EXPAT: /usr/local/lib/libexpat.so (found version "2.1.0") 
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
-- Using third-party bundled libsqlite3
-- Could NOT find DOUBLE_CONVERSION (missing:  DOUBLE_CONVERSION_LIBRARY DOUBLE_CONVERSION_INCLUDE_DIR) 
-- Using third-party bundled double-conversion
-- Could NOT find LZ4 (missing:  LZ4_LIBRARY LZ4_INCLUDE_DIR) 
-- Using third-party bundled LZ4
-- Could NOT find FastLZ (missing:  FASTLZ_LIBRARY FASTLZ_INCLUDE_DIR) 
-- Using third-party bundled fastlz
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
-- Could NOT find LIBZIP (missing:  LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR_ZIP LIBZIP_INCLUDE_DIR_ZIPCONF) 
-- Using third-party bundled libzip
CMake Error at CMake/FindICU.cmake:91 (MESSAGE):
  Could not find ICU
Call Stack (most recent call first):
  CMake/HPHPFindLibs.cmake:179 (find_package)
  CMake/HPHPSetup.cmake:97 (include)
  third-party/CMakeLists.txt:18 (include)

ICU が足りない

$ sudo pkg install icu    
Updating Avalon repository catalogue...
Avalon repository is up-to-date.
All repositories are up-to-date.
The following 1 packages will be affected (of 0 checked):

New packages to be INSTALLED:
        icu: 53.1

The process will require 58 MB more space.
13 MB to be downloaded.

Proceed with this action? [y/N]: y
Fetching icu-53.1.txz: 100%   13 MB 946.3k/s    00:14    
Checking integrity... done (0 conflicting)
[1/1] Installing icu-53.1...
[1/1] Extracting icu-53.1: 100%

ビルド

-- Could NOT find LIBGLOG (missing:  LIBGLOG_LIBRARY LIBGLOG_INCLUDE_DIR) 
-- Could NOT find LIBINOTIFY (missing:  LIBINOTIFY_LIBRARY LIBINOTIFY_INCLUDE_DIR) 
-- MySQL Include dir: /usr/local/include/mysql  library dir: /usr/local/lib/mysql
-- MySQL client libraries: mysqlclient_r
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
-- System PCRE does not have JIT enabled - will use hhvm-third-party/pcre
-- Found libevent: /usr/local/lib/libevent.so
-- Could NOT find LibUODBC (missing:  LIBODBC_LIBRARIES LIBODBC_INCLUDE_DIRS) 
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
-- Using third-party bundled libsqlite3
-- Could NOT find DOUBLE_CONVERSION (missing:  DOUBLE_CONVERSION_LIBRARY DOUBLE_CONVERSION_INCLUDE_DIR) 
-- Using third-party bundled double-conversion
-- Could NOT find LZ4 (missing:  LZ4_LIBRARY LZ4_INCLUDE_DIR) 
-- Using third-party bundled LZ4
-- Could NOT find FastLZ (missing:  FASTLZ_LIBRARY FASTLZ_INCLUDE_DIR) 
-- Using third-party bundled fastlz
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
-- Could NOT find LIBZIP (missing:  LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR_ZIP LIBZIP_INCLUDE_DIR_ZIPCONF) 
-- Using third-party bundled libzip
-- Found ICU header files in /usr/local/include
-- Found ICU libraries: /usr/local/lib/libicuuc.so
-- Can't find minimal tcmalloc
ERROR: Unable to find Intel TBB install directory. 
CMake Error at CMake/HPHPFindLibs.cmake:277 (if):
  if given arguments:

    "LESS" "5005"

  Unknown arguments specified
Call Stack (most recent call first):
  CMake/HPHPSetup.cmake:97 (include)
  third-party/CMakeLists.txt:18 (include)

TBB が足りない?

Threading Building Blocks

ここからダウンロードしてきたけど Dragonfly だと使えない. これがビルドできないと動かなそうなので失敗で終了っぽい.

ruby 2.2.0 インストールログ

環境

  • DragonFly v4.0.1.2.gf72e0-RELEASE
  • ruby-2.2.0

手順

$ curl -O http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.0.tar.gz
$ tar xvf ruby-2.2.0
$ cd ruby-2.2.0
$ ./configure --prefix=/path/to/install --enable-shared
$ sudo pkg install libffi-3.2.1 # ないと fiddle のビルドがこけ続ける
$ make
$ make install

ちなみに rbenv 使ってるけど ruby-build で試しにやりなおしてみても同じエラーが出る.そっちのほうも出たってことは --enable-shared 必要ってことかな.

DragonflyBSD 4.0 あたりで sudo したあとプロセスがゾンビ化する場合は sudo を update しよう

環境

  • DragonFly v4.0.1.2.gf72e0-RELEASE
  • sudo 1.8.11 p1

現象

sudo を使うとそのコマンドを実行した後に入力はおろか Ctrl+C なども効かなくなる. root になって実行するのは問題なかった.

チケットなど

どうやら DragonflyBSD + sudo 1.8.11 で問題があってにパッチをあてると直るらしい.

対処法

pkg upgrade したらいつの間にか直ってた. ログを見ると下記のように reinstall してる様子.

dragonfly pkg: sudo reinstalled: 1.8.11.p1 -> 1.8.11.p1

java で 二つの Map のキー部分が重複する場合しない場合を分ける実装はどうすれば?

問題

二つのマップが与えられる

Map<Integer, String> map1;
Map<Integer, String> map2;

この二つのマップでそれらに含まれる任意のキーに対して

  • 両方に値がある場合
  • map1 にのみ値がある場合
  • map2 にのみ値がある場合

を考慮した実装を行いたい.このような場合にどう実装すべきか?

実装

愚直に実装した場合

毎回書くのめんどいのでなんか簡単な書き方かうまいことメソッドにできればうれしい.

Set<Integer> set = new HashSet<>(map1.keySet());
set.addAll(map2.keySet());
foreach (Integer key : set) {
    String value1 = map1.get(key);
    String value2 = map2.get(key);
    if (value1 != null && value2 != null) {
      // 両方に値がある場合
    } else if (value1 != null && value2 == null) {
      // map1 にのみ値がある場合
    } else if (value1 == null && value2 != null) {
      // map2 にのみ値がある場合
    }
}

MySQL の JDBC ドライバのサービスプロバイダの設定は Ant で生成されてた

https://docs.oracle.com/javase/8/docs/api/java/sql/DriverManager.html

The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver. For example, to load the my.sql.Driver class, the META-INF/services/java.sql.Driver file would contain the entry:

my.sql.Driver

https://docs.oracle.com/javase/jp/6/api/java/sql/DriverManager.html

DriverManager メソッド getConnection と getDrivers は、Java Standard Edition サービスプロバイダメカニズムをサポートするように拡張されました。JDBC 4.0 ドライバは、ファイル META-INF/services/java.sql.Driver を含める必要があります。このファイルには、java.sql.Driver の JDBC ドライバ実装の名前が含まれます。たとえば my.sql.Driver クラスをロードするために、META-INF/services/java.sql.Driver ファイルに次のエントリが含まれます。

my.sql.Driver

なのでへ~と思って mysqlJDBC ドライバのコード見てみる.

$ curl -L -O https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.34.tar.gz
$ tar xvf mysql-connector-java-5.1.34.tar.gz
$ cd mysql-connector-java-5.1.34

どっかに java.sql.Driver という記述ないかなーと探してみたらなんと build.xml の中に書かれた.

 548         <!-- JDBC4+ support of service provider mechanism. -->
 549         <mkdir dir="${buildDir}/${fullProdName}/META-INF/services/" />
 550         <echo file="${buildDir}/${fullProdName}/META-INF/services/java.sql.Driver"
 551               message="com.mysql.jdbc.Driver${line.separator}com.mysql.fabric.jdbc.FabricMySQLDriver" />

CHANGES を見ると 5.0 担った時に追加されたのねー.

2248 12-23-05 - Version 5.0.0-beta
...
2308     - Added service-provider entry to META-INF/services/java.sql.Driver
2309       for JDBC-4.0 support.

という感想.

っていうか他にも書かれたところかかれてないということは java.sql.DriverManager 経由で取得できるドライバって普通 FabricMySQLDriver が使われるってことですかね.

と思ったけどよく見たら line.separator で区切られてるので下記二つのドライバが読み込まれるってことっぽいですね.

ってことで build.xml で echo できるってのと Fabric 用のドライバってデフォルトでセットされてるんですねって知見が得られた.

nise-nabe/mysql-driver-test · GitHub

isucon4 予選参加記

下記イベントの参加記です.

優勝賞金100万円!今年もやります 第4回 ISUCON 開催と日程のお知らせ #isucon : ISUCON公式Blog http://isucon.net/archives/38857424.html

去年と同じように一日目に「パイの実g」で参加していました. 予選の問題詳細の記事出たらリンク追加予定.追記しました.

ISUCON4 予選問題の解説と講評 & AMIの公開 : ISUCON公式Blog

http://isucon.net/archives/40724693.html

結論

Score: 2677

実装に失敗して初期状態で動かしたベンチのスコアがそのまま結果となっています.

箇条書き

ここの記述はチームというより自分の考えのみを記述しています.

自分の簡単なスキルセット

  • 主にコード書く人
    • Go まあ読み書きできる
    • PHP まあ読み書きできる
  • サーバ構築とかは趣味で軽くやるレベル
    • 金がないので AWS の知識はほぼない
  • isucon とかチューニンガソンとか出たことある

開始前

事前に考えていた戦略

  • 基本 Go で最悪 PHP を使う
    • Go
      • たぶん早い
      • ただでかい修正入れるほど習熟してなさそうなのでやるならちまちまコード変更程度でがんばるぐらいでしょう
    • PHP
      • 大きな改善点見つからない場合ノウハウみつかりやすいのでちまちまコード最適化したりパラメータいじって戦えるかなと
      • Phalcon 書き換えならできなくはないので検討
  • 重そうな修正を時間的に早めにやって終盤軽めのを選んでやる
    • ミドルウェアの設定とかはわりとノウハウ転がってるので最悪コピペすればよさそう
    • 早めに着手すると固執したり実装によっては無意味になる可能性があるのでできれば後のほうでやりたい
  • キャッシュ出来るところはする
    • 去年の isucon やチューニンガソンなどの教訓
  • ベンチのオプション確認する
    • 去年 isucon で workload の存在に気付かなかった教訓
  • バージョン入れ替えとかは余裕があればやればやるけど多分そんなスキルはなさそうのでやらない
  • できれば人数分インスタンス立ててそれぞれやったほうが効率良さそう
    • AWS クーポン来たのでそれの範囲内でやるために 1 台で考えることにした(若干敗因理由)

開始後

確認時やったこと

  • アプリ触る
  • query.log で全部出して 傾向見る
  • slow_query.log でチューニング部分に当たりをつける
  • コード軽く読む
    • 自分は手元に PhpStorm があったので挙動把握は php 読んでた
    • どこかキャッシュ使えないかなとか

簡単に確認した後の感想

対象アプリ触って

  • フィッシングサイトっぽい
  • 見る感じページは二つでログインフォームとログイン後フォームっぽい
  • ログインフォームは失敗時にフォームのページに戻ってきてエラーメッセージ出すっぽい
  • ログイン後になんか動的に出力するものがあるページを表示するっぽい
  • ベンチ走らせてなくても isucon-bank.png の画像取得に成功したり失敗したりするなぁ(勘違い?)

改善に関して

  • Go は martini かー 知らないなー フレームワーク重そうだなー
  • テーブル少ない( users と login_log の二つ) 簡単に手は入れられそう
  • ユーザの追加などの更新はない オンメモリにできる?
  • login_log の INSERT 重い 消したい
  • テンプレート少ない キャッシュしやすい? と思ったけどログイン後の情報必要なので無理かなぁ.

感想から簡単な戦略

Go 使うかー

軽 中 重 で自分の感覚でコストを考えつつ打てる手を考えた結果

  • (軽)テーブルやカラムは少ないためインデックスなどのチューニングはさくっとできそう
  • (中)ユーザ情報はオンメモリにできそう
  • (重)INSERT なくそう
  • (軽)静的ファイルをフロントでうまく返そう

無視

  • Go のフレームワーク変える(というか外す) -> 今のスキルじゃバグ無し変更はたぶん無理

方針決定後

当初の予定通り重いのからやろうとしたので INSERT なくすあたりに手を出す. (終わったらミドルウェアの設定やるつもりだった.)

作業内容見積もり

  • コード読んでテーブル設計する
    • users に最終ログイン情報突っ込む
    • BAN の ip と user は別っぽいので ip でテーブル作る
  • 変更したテーブルに合わせてコード変更する
  • テーブル変更に対応した初期化スクリプト

担当分担

ここらへん記憶が曖昧

  • 初期化スクリプト書く人
  • コード変更する人
  • コード変更する人 && 方針が正しいか検討する人

作業

ハマった所

  • 初期化スクリプト
    • webapp のライブラリを使いまわそうとするも失敗してて時間食ってた様子
  • BAN 対象の ip や user の決定方法
    • コードが結構わかりにくかった
      • クエリ複雑
      • コピペミスでわざとバグっぽい書き方してるのかと勘ぐる (rowsB 作った後に rows 参照してるあたり)
    • テーブルに存在しない login(カラム名) は必要なのかどうか
      • たぶん要らないと判断
  • BAN 対象の ip や user の更新
    • SQL 間違いまくる
    • (ここの修正ができなかったため 0 点)
  • last_login 情報
    • なんで limit 2 してる?
      • ログイン情報がないときに今ログインした結果を使うためか!
    • /mypage じゃなくて /login 時にいろいろ session にもたせるようにしよう
      • session に入れた値がテンプレ側で nil になり panic
  • martini
    • よくわからん
  • /report の並び順ってなに?
    • 多分 primary key 順なんだろうけどよく調べてないのでなんでもいいものと決めてかかる
    • 正しい判断かどうか不明

結果

Score: 2677

いろいろ対応した環境が正しく動かなかったため初期状態のスコアがそのままとなりました. 以下は予選終了の時点での状態です. ami 公開されたら他の参加者のやりかたとかみながらバグ修正したい

  • 表示上の Score: 17000
  • /report の結果が正しくないのでスコア 0
  • nginx や mysql の設定まったく未修正
  • そういやインデックスも全く手をつけてない
  • 最終ログインの情報と BAN 情報とログイン失敗回数を users にもたせる修正
  • BAN 対象の ip を確保するテーブルの作成およびBAN 情報とログイン失敗回数をもたせる

反省的な(初歩的)

  • 実質 13:00 ぐらいから活動開始してたのでもっと早く起きましょう
  • AC アダプタ忘れないようにしないと電源きれて他の PC 使うとき打鍵感とかキー配列違うのはやばい
  • クーポン来たのでインスタンス一つしか立てなかったけど勝つ気なら人数ぶんインスタンス合ったほうが良さそうね
  • 一人が作業中にちょっと改良的なもの全然できなかったし
  • 一つのユーザとかだと複数人で同じユーザだと vim で死ぬとか素の vim かわからん謎の挙動とかつらいね

最後に

参加者のみなさんお疲れ様でした! 運営のみなさんありがとうございました!