Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Erlang VM reduction count 'bumps' to all NIF calls

  • Loading branch information...
commit 51e55c2e13ca7d0cf180e5e6446a86f29ccdbfcb 1 parent 6e58a37
@slfritchie slfritchie authored
Showing with 90 additions and 12 deletions.
  1. +30 −0 src/bitcask_bump.erl
  2. +60 −12 src/bitcask_nifs.erl
View
30 src/bitcask_bump.erl
@@ -0,0 +1,30 @@
+%% -------------------------------------------------------------------
+%%
+%% bitcask: Eric Brewer-inspired key/value store
+%%
+%% Copyright (c) 2010 Basho Technologies, Inc. All Rights Reserved.
@chardan
chardan added a note

Please up-date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+%%
+%% This file is provided to you 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.
+%%
+%% -------------------------------------------------------------------
+-module(bitcask_bump).
+
+-export([big/0, small/0]).
+
+big() ->
+ erlang:bump_reductions(1500).
+
+small() ->
+ erlang:bump_reductions(500).
View
72 src/bitcask_nifs.erl
@@ -332,7 +332,11 @@ keydir_release(_Ref) ->
end.
-lock_acquire(_Filename, _IsWriteLock) ->
+lock_acquire(Filename, IsWriteLock) ->
+ bitcask_bump:big(),
+ lock_acquire_int(Filename, IsWriteLock).
+
+lock_acquire_int(_Filename, _IsWriteLock) ->
case random:uniform(999999999999) of
666 -> {ok, make_ref()};
667 -> {error, enoent};
@@ -341,13 +345,21 @@ lock_acquire(_Filename, _IsWriteLock) ->
_ -> exit("NIF library not loaded")
end.
-lock_release(_Ref) ->
+lock_release(Ref) ->
+ bitcask_bump:big(),
+ lock_release_int(Ref).
+
+lock_release_int(_Ref) ->
case random:uniform(999999999999) of
666 -> ok;
_ -> exit("NIF library not loaded")
end.
-lock_readdata(_Ref) ->
+lock_readdata(Ref) ->
+ bitcask_bump:big(),
+ lock_readdata_int(Ref).
+
+lock_readdata_int(_Ref) ->
case random:uniform(999999999999) of
666 -> {fstat_error, random:uniform(4242)};
667 -> {error, allocation_error};
@@ -356,7 +368,11 @@ lock_readdata(_Ref) ->
_ -> exit("NIF library not loaded")
end.
-lock_writedata(_Ref, _Data) ->
+lock_writedata(Ref, Data) ->
+ bitcask_bump:big(),
+ lock_writedata_int(Ref, Data).
+
+lock_writedata_int(_Ref, _Data) ->
case random:uniform(999999999999) of
666 -> {ftruncate_error, random:uniform(4242)};
667 -> {pwrite_error, random:uniform(4242)};
@@ -365,28 +381,60 @@ lock_writedata(_Ref, _Data) ->
_ -> exit("NIF library not loaded")
end.
-file_open(_Filename, _Opts) ->
+file_open(Filename, Opts) ->
+ bitcask_bump:big(),
+ file_open_int(Filename, Opts).
+
+file_open_int(_Filename, _Opts) ->
erlang:nif_error({error, not_loaded}).
-file_close(_Ref) ->
+file_close(Ref) ->
+ bitcask_bump:big(),
+ file_close_int(Ref).
+
+file_close_int(_Ref) ->
erlang:nif_error({error, not_loaded}).
-file_sync(_Ref) ->
+file_sync(Ref) ->
+ bitcask_bump:big(),
+ file_sync_int(Ref).
+
+file_sync_int(_Ref) ->
erlang:nif_error({error, not_loaded}).
-file_pread(_Ref, _Offset, _Size) ->
+file_pread(Ref, Offset, Size) ->
+ bitcask_bump:big(),
+ file_pread_int(Ref, Offset, Size).
+
+file_pread_int(_Ref, _Offset, _Size) ->
erlang:nif_error({error, not_loaded}).
-file_pwrite(_Ref, _Offset, _Bytes) ->
+file_pwrite(Ref, Offset, Bytes) ->
+ bitcask_bump:big(),
+ file_pwrite_int(Ref, Offset, Bytes).
+
+file_pwrite_int(_Ref, _Offset, _Bytes) ->
erlang:nif_error({error, not_loaded}).
-file_read(_Ref, _Size) ->
+file_read(Ref, Size) ->
+ bitcask_bump:big(),
+ file_read_int(Ref, Size).
+
+file_read_int(_Ref, _Size) ->
erlang:nif_error({error, not_loaded}).
-file_write(_Ref, _Bytes) ->
+file_write(Ref, Bytes) ->
+ bitcask_bump:big(),
+ file_write_int(Ref, Bytes).
+
+file_write_int(_Ref, _Bytes) ->
erlang:nif_error({error, not_loaded}).
-file_seekbof(_Ref) ->
+file_seekbof(Ref) ->
+ bitcask_bump:big(),
+ file_seekbof_int(Ref).
+
+file_seekbof_int(_Ref) ->
erlang:nif_error({error, not_loaded}).
Please sign in to comment.
Something went wrong with that request. Please try again.