Permalink
Browse files

Merge branch 'pool'

Conflicts:
	README.md
  • Loading branch information...
Ali Yakamercan
Ali Yakamercan committed Dec 15, 2012
2 parents 8763adf + e6fe529 commit 04698ea93a0e5d91f5f740ff4ea2811a1c59d36d
View
@@ -2,35 +2,85 @@ CBERL
====
NIF based Erlang bindings for couchbase based on libcouchbase.
-CBERL is at very early stage of development, it only supports very basic functionality. Please submit bugs and patches if you find any.
-Only tested on mac so far.
+CBERL is at early stage of development, it only supports very basic functionality. Please submit bugs and patches if you find any.
+Only tested on mac and amazon linux so far.
-Quick Start
+Quick Setup/Start
---------
-You must have libcouchbase installed. For more information how to visit: http://www.couchbase.com/develop/c/current. You can then normally compile or include it in your project.
+First you must have libcouchbase installed.
+
+On mac install [homebrew](http://mxcl.github.com/homebrew/,"homebrew") if you haven't already then run:
+
+ brew install https://github.com/couchbase/homebrew/raw/stable/Library/Formula/libcouchbase.rb
+
+On Amazon linux:
+
+ sudo wget -O/etc/yum.repos.d/couchbase.repo http://packages.couchbase.com/rpm/couchbase-centos62-x86_64.repo
+ sudo yum check-update
+ sudo yum install --enablerepo=epel libcouchbase2 libcouchbase-devel
+
+For installing libcouchbase on other systems visit http://www.couchbase.com/develop/c/current.
+
+
+Then:
+
+ git clone git@github.com:aliyakamercan/cberl.git
+ cd cberl
+ ### assuming you have rebar in your path
+ rebar get-deps compile
+
+Or just include it as a dependency in your rebar config.
- ./rebar compile
- erl -pa ebin deps/jiffy/ebin
Example
-------
Make sure you have couchbase running on localhost or use cberl:new(Host) instead.
- 1> {ok, Instance} = cberl:new().
- {ok,{instance,<<>>,cberl_transcoder}}
- 2> cberl:set(Instance, "fkey", 0, "cberl").
+ %% create a connection pool of 5 connections named cberl_default
+ %% you can provide more argument like host, username, password,
+ %% bucket and transcoder - look at [cberl.erl](https://github.com/aliyakamercan/cberl/blob/master/src/cberl.erl) for more detail
+ cberl:start_link(cberl_default, 5).
+ {ok, <0.33.0>}
+ %% Poolname, Key, Expire - 0 for infinity, Value
+ cberl:set(cberl_default, "fkey", 0, "cberl").
ok
- 3> cberl:get(Instance, "fkey").
- {ok,0,"cberl"}
+ cberl:get(cberl_default, "fkey").
+ {"fkey", ReturnedCasValue, "cberl"}
+
+
+For more information on all the functions -> ./rebar doc (most of documentation is out of date right now)
+
+Custom Transcoders
+-----
+
+You can have your custom transcoders, your transcoder must export 3 functions:
+
+__encode_value/2:__
+
+Takes in an encoder|encoder list and the original value and turns it into a binary.
+
+__decode_value/2:__
+
+Takes in a flag (from couchbase) and the value (as binary) and turns it into the actual value.
+
+__flag/1:__
+
+Turns an encoder_name (or list of them) into an integer. This value is sent to CB during set operations and this is what you get in decode value. You must return a value for 'standart' encoder if you are not planning to specify an encoder for every set operation.
+
+Check out [cberl_transcoder.erl](https://github.com/aliyakamercan/cberl/blob/master/src/cberl_transcoder.erl) it is pretty straightforward.
+
+Performance
+-------
-For more information on all the functions -> ./rebar doc
+I included [results](https://github.com/aliyakamercan/cberl/blob/pool/bench/macbook_cberl.png) of [basho_bench](http://docs.basho.com/riak/latest/cookbooks/Benchmarking/) which I ran on my mac. It is the results of 100 processes using a pool of 5 connections. Anyways this is pretty meaningless
+ since requirements and system specifications change all the time. I included basha_bench driver and config file under bench. Please tweak the config file for your requirement and run your own benchmarks.
TODO
----
-1) Write more tests
+1) Update documentation
-2) Add informational methods
+2) Add missing methods (querying documents and informational methods)
-3) Make function signatures more compatible with other couchbase clients
+3) Write more tests
@@ -0,0 +1,45 @@
+-module(basho_bench_driver_cberl).
+
+-export([new/1,
+ run/4
+ ]).
+
+-include("basho_bench.hrl").
+
+new(_Id) ->
+ PoolSize = basho_bench_config:get(cberl_pool_size, 5),
+ HostPort = basho_bench_config:get(cberl_hostport, "localhost:8091"),
+ UserName = basho_bench_config:get(cberl_username, ""),
+ Password = basho_bench_config:get(cberl_password, ""),
+ cberl:start_link(bench_testing, PoolSize, HostPort, UserName, Password),
+ {ok, bench_testing}.
+
+run(get, KeyGen, _ValueGen, PoolName) ->
+ Key = KeyGen(),
+ case cberl:get(PoolName, Key) of
+ {Key, _Cas, _Value} ->
+ {ok, PoolName};
+ {Key, {error, key_enoent}} ->
+ {ok, PoolName};
+ {Key, {error, Error}} ->
+ {error, Error, PoolName};
+ Error ->
+ {error, Error, PoolName}
+ end;
+run(set, KeyGen, _ValueGen, PoolName) ->
+ Key = KeyGen(),
+ Value = rand_val(50),
+ case cberl:set(PoolName, Key, 60, Value) of
+ ok ->
+ {ok, PoolName};
+ Error ->
+ {error, Error, PoolName}
+ end.
+
+rand_val(N) ->
+ rand_val(N, []).
+
+rand_val(0, Acc) ->
+ Acc;
+rand_val(N, Acc) ->
+ rand_val(N - 1, [random:uniform(26) + 96 | Acc]).
View
@@ -0,0 +1,27 @@
+{mode, max}.
+
+% Run X operations per second per worker
+% {mode, {rate, X}}
+
+{duration, 1}.
+
+{concurrent, 100}.
+
+{driver, basho_bench_driver_cberl}.
+
+%% code path to cberl/jiffy/poolboy
+{code_paths, ["*/cberl",
+ "*/cberl/deps/poolboy",
+ "*/cberl/deps/jsx"]}.
+
+{key_generator, {int_to_str, {uniform_int, 100000}}}.
+
+{value_generator, {uniform_bin, 100, 2000}}.
+
+{operations, [{set, 1}, {get, 1}]}.
+
+%% cberl configs
+{cberl_pool_size, 5}.
+{cberl_hostport, "localhost:8091"}.
+{cberl_username, ""}.
+{cberl_password, ""}.
View
Binary file not shown.
View
@@ -2,7 +2,6 @@
#define CALLBACKS_H
#include <stdio.h>
-#include "config.h"
#include <string.h>
#include <libcouchbase/couchbase.h>
View
@@ -1,186 +0,0 @@
-/* src/config.h. Generated from config.h.in by configure. */
-/* src/config.h.in. Generated from configure.ac by autoheader. */
-
-
-#ifndef CONFIG_H
-#define CONFIG_H
-/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/*
- * Copyright 2010, 2011 Couchbase, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * This file is generated by running configure. Any changes you make to this
- * file will be overwritten the next time you run configure. If you want to
- * make permanent changes to the file you should edit configure.ac instead.
- * All platform-specific includes should be placed inside config_static.h
- * to keep the config.h as small as possible. That allows us for easily
- * use another build systems with a poor support for automake (like Windows)
- *
- * @author Trond Norbye
- */
-
-
-/* Define to 1 if you have the `clock_gettime' function. */
-/* #undef HAVE_CLOCK_GETTIME */
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#define HAVE_DLFCN_H 1
-
-/* Define to 1 if you have the <event.h> header file. */
-#define HAVE_EVENT_H 1
-
-/* Define to 1 if you have the `gethrtime' function. */
-/* #undef HAVE_GETHRTIME */
-
-/* Define to 1 if you have the `gettimeofday' function. */
-#define HAVE_GETTIMEOFDAY 1
-
-/* Have ntohll */
-/* #undef HAVE_HTONLL */
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#define HAVE_INTTYPES_H 1
-
-/* We have libevent2 */
-#define HAVE_LIBEVENT2 1
-
-/* Define to 1 if you have the <libvbucket/vbucket.h> header file. */
-#define HAVE_LIBVBUCKET_VBUCKET_H 1
-
-/* We have libyajl2 */
-/* #undef HAVE_LIBYAJL2 */
-
-/* Define to 1 if you have the <mach/mach_time.h> header file. */
-/* #undef HAVE_MACH_MACH_TIME_H */
-
-/* Define to 1 if you have the <memory.h> header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the <netdb.h> header file. */
-#define HAVE_NETDB_H 1
-
-/* Define to 1 if you have the <netinet/in.h> header file. */
-#define HAVE_NETINET_IN_H 1
-
-/* Define to 1 if you have the `QueryPerformanceCounter' function. */
-/* #undef HAVE_QUERYPERFORMANCECOUNTER */
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#define HAVE_STDINT_H 1
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the <strings.h> header file. */
-#define HAVE_STRINGS_H 1
-
-/* Define to 1 if you have the <string.h> header file. */
-#define HAVE_STRING_H 1
-
-/* Use system internal sasl */
-/* #undef HAVE_SYSTEM_LIBSASL */
-
-/* Define to 1 if you have the <sys/socket.h> header file. */
-#define HAVE_SYS_SOCKET_H 1
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the <sys/time.h> header file. */
-#define HAVE_SYS_TIME_H 1
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#define HAVE_UNISTD_H 1
-
-/* Define to 1 if you have the <winsock2.h> header file. */
-/* #undef HAVE_WINSOCK2_H */
-
-/* Define to 1 if you have the <ws2tcpip.h> header file. */
-/* #undef HAVE_WS2TCPIP_H */
-
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
- */
-#define LT_OBJDIR ".libs/"
-
-/* Define to 1 if your C compiler doesn't accept -c and -o together. */
-/* #undef NO_MINUS_C_MINUS_O */
-
-/* Name of package */
-#define PACKAGE "libcouchbase"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT "support@couchbase.com"
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME "libcouchbase"
-
-/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "libcouchbase 1.1.0dp7_43_gd9e354e"
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME "libcouchbase"
-
-/* Define to the home page for this package. */
-#define PACKAGE_URL ""
-
-/* Define to the version of this package. */
-#define PACKAGE_VERSION "1.1.0dp7_43_gd9e354e"
-
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Enable extensions on AIX 3, Interix. */
-#ifndef _ALL_SOURCE
-# define _ALL_SOURCE 1
-#endif
-/* Enable GNU extensions on systems that have them. */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE 1
-#endif
-/* Enable threading extensions on Solaris. */
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# define _POSIX_PTHREAD_SEMANTICS 1
-#endif
-/* Enable extensions on HP NonStop. */
-#ifndef _TANDEM_SOURCE
-# define _TANDEM_SOURCE 1
-#endif
-/* Enable general extensions on Solaris. */
-#ifndef __EXTENSIONS__
-# define __EXTENSIONS__ 1
-#endif
-
-
-/* Version number of package */
-#define VERSION "1.1.0dp7_43_gd9e354e"
-
-/* Define to 1 if on MINIX. */
-/* #undef _MINIX */
-
-/* Define to 2 if the system does not provide POSIX.1 features except with
- this defined. */
-/* #undef _POSIX_1_SOURCE */
-
-/* Define to 1 if you need to in order for `stat' and other things to work. */
-/* #undef _POSIX_SOURCE */
-
-
-#include "config_static.h"
-#endif
-
Oops, something went wrong.

0 comments on commit 04698ea

Please sign in to comment.