---
title: "写给高性能数据库引擎coolhash"
author: "xiaoZ5919"
date: "2014-05-27T16:54:10Z"
tags: []
categories: ["企业架构"]
slug: "coolhash"
draft: false
lastmod: "2014-05-27T17:36:02Z"
id: 2072209
url: "https://xiaoz5919.iteye.com/blog/2072209"
---

前一段时间fourinone在ITEYE资讯上发表了一篇<http://www.iteye.com/news/29025-Fourinone-CoolHash>高性能数据库引擎产品宣言，我回复评论说玩得酷，还要考得住，借用一些企鹅手机管家的台词，结果被fourinone十分不满意。又把我骂了一顿，我继续回击。面试的时候流行一句话，talk is cheap,show me the code，我在此又借用了一下，talk is cheap，show the benchmark！自此我每天一贴呼唤fourinone拿出benchmark，但至此他都没有回应！好吧我就自己动手看看CoolHash的高性能，我使用fourinone提到的4.05.06，进行了100并发100w请求的benchmark，并将代码放在<https://git.oschina.net/zhh5919/fourinonetest>不料在并发场景下CoolHash就会抛出异常，啊高性能啊！
详细过程如下：
搞这个东东，目的只有一个让我们看看fourinone coolhash的所谓高性能。 搞起来的步骤：

首先将项目导入eclipse中，会自动编译代码到bin目录，同时会将fourinone.jar copy到该 目录下，这个很重要，因为在fourinone提供的指南demo也是这么玩，尽量和他的demo一致， 要不fourinone会说你使用姿势不正确的。
启动CoolHashServer 从命令行cmd下进入bin目录。然后执行 java -cp fourinone.jar; RunServer 然后看到启动log Start ParkService and waiting 4 seconds... Start CoolHashService and waiting 5 seconds... Please try connect to CoolHashServer now. ok CoolHashServer启动成功啊
简单的benchmark，CoolHash只提供单线程的读写，而且仅仅是单线程写入几十个数据， 如果把他叫做benchmark，我想你看到这里，一定是呵呵 哈哈…… 那我们给他加点压力吧，100并发100w次请求，我想这不是什么难事儿吧！mongodb， ideawu开源的SSDB都能轻松做到，让我们来见识一下CoolHash看看行不行，我写了一段 模拟100并发100w请求的代码，在EasyCoolHashDemo，各位看官也可以帮我review一下。 执行看看吧！ java -cp .;fourinone.jar EasyCoolHashDemo

    执行结果让我差点崩溃了，哦不是我崩溃，是我的电脑崩溃了，cpu几乎100%。 我的电脑配置i5-3470 3.2GHz的，内存4G，win7系统。 惊喜的是哪有这些~ 根本执行不了，就不断地报错~ 欢迎更多的小伙伴来按上面的步骤 试试看看有木有报错！ @fourinone啊 这就你所说的高性能，不是单线程写入几十个kv，然后每个kv都秒级别 就是高性能了


 INFO: DataWorker Number:8
Exception in thread "Thread-9" java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at com.fourinone.FileAdapter$1.getBytes(FileAdapter.java:317) at com.fourinone.ConstantBit$Target$1.getBytes(ConstantBit.java:22) at com.fourinone.ConstantBit$Target.getTargetBytes(ConstantBit.java:175)

    at com.fourinone.DumpCtor.put(DumpCtor.java:208)
    at EasyCoolHashDemo$Worker.run(EasyCoolHashDemo.java:39)
    at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-56" java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at com.fourinone.FileAdapter$1.getBytes(FileAdapter.java:317) at com.fourinone.ConstantBit$Target$1.getBytes(ConstantBit.java:22) at com.fourinone.ConstantBit$Target.getTargetBytes(ConstantBit.java:175)

    at com.fourinone.DumpCtor.put(DumpCtor.java:208)
    at EasyCoolHashDemo$Worker.run(EasyCoolHashDemo.java:39)
    at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-81" java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at com.fourinone.FileAdapter$1.getBytes(FileAdapter.java:317) at com.fourinone.ConstantBit$Target$1.getBytes(ConstantBit.java:22) at com.fourinone.ConstantBit$Target.getTargetBytes(ConstantBit.java:175)

    at com.fourinone.DumpCtor.put(DumpCtor.java:208)
    at EasyCoolHashDemo$Worker.run(EasyCoolHashDemo.java:39)
    at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-70" java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at com.fourinone.FileAdapter$1.getBytes(FileAdapter.java:317) at com.fourinone.ConstantBit$Target$1.getBytes(ConstantBit.java:22) at com.fourinone.ConstantBit$Target.getTargetBytes(ConstantBit.java:175)

    at com.fourinone.DumpCtor.put(DumpCtor.java:208)
    at EasyCoolHashDemo$Worker.run(EasyCoolHashDemo.java:39)
    at java.lang.Thread.run(Unknown Source)