Skip to content

Instantly share code, notes, and snippets.

@fdmanana
fdmanana / gist:1034290
Created June 19, 2011 13:40
replicator, shared/dedicated httpc pool configuration
diff --git a/src/couchdb/couch_api_wrap.erl b/src/couchdb/couch_api_wrap.erl
index 63e607a..8fcd08f 100644
--- a/src/couchdb/couch_api_wrap.erl
+++ b/src/couchdb/couch_api_wrap.erl
@@ -101,7 +101,6 @@ db_open(DbName, Options, Create) ->
end.
db_close(#httpdb{httpc_pool = Pool}) ->
- unlink(Pool),
ok = couch_httpc_pool:stop(Pool);
@fdmanana
fdmanana / gist:1034294
Created June 19, 2011 13:46
replicator always retry on attachment streaming failure
diff --git a/src/couchdb/couch_api_wrap.erl b/src/couchdb/couch_api_wrap.erl
index aa481c7..63e607a 100644
--- a/src/couchdb/couch_api_wrap.erl
+++ b/src/couchdb/couch_api_wrap.erl
@@ -597,7 +597,7 @@ doc_from_multi_part_stream(ContentType, DataFun) ->
started ->
unlink(Parser),
exit(Parser, kill),
- restart_remote_open_doc_revs();
+ restart_att_streaming();
@fdmanana
fdmanana / gist:1092157
Created July 19, 2011 12:37
Erlang skew data structure (priority queue for functional languages)
-module(skew).
-export([new/0, size/1, in/3, out/2, min/1]).
-define(null, []).
new() ->
?null.
size(?null) ->
@fdmanana
fdmanana / user_default.erl
Created August 24, 2011 17:56 — forked from dustin/user_default.erl
Helpful stuff for figuring out what's going on in there...
-module(user_default).
-export([proc_count/1, proc_count/0,
proc_mem/2, proc_mem/1, proc_mem/0,
matching/2, matching/1]).
proc_info(X, Info) ->
case proplists:get_value(X, Info) of
{proc_lib, init_p, _} ->
@fdmanana
fdmanana / gist:1199903
Created September 7, 2011 06:21
Erlang OTP R14B, Mac OS X Lion 64bits and XCode 4.1

Issue

On Mac OS X Lion (64bits at least), we get random "Bus error 10" (or "Segmentation fault: 11") crashes if init:restart/0 is called and the crypto application is loaded. Why? XCode 4.1 ships an OpenSSL version that deprecates many functions used by OTP's crypto NIF (lib/crypto/c_src/crypto.c).

Example:

$ erl
@fdmanana
fdmanana / gist:1343454
Created November 6, 2011 20:47
Erlang/OTP gen_server simplified API, basics

Client side API

Start a gen_server programmatically

gen_server:start(ModuleName, Arguments, Options) -> {ok, Pid} | {error, Reason}

gen_server:start(ServerName, ModuleName, Arguments, Options) -> {ok, Pid} | {error, Reason}

# comment lines start with a sharp (#)
{
"type": "#{pick(human,orc,elf,dwarf)}",
"category": "#{pick(warrior,assassin,thief,wizard)}",
"ratio": #{random_int(0, 1)}.#{random_int(0, 9)},
"level": #{random_int(1, 20)},
"data1": "#{random_string(40)}",
"data2": "#{random_string(50)}",
"data3": "#{random_string(35)}",
Before COUCHDB-1186
fdmanana 23:21:05 ~/git/hub/slow_couchdb (master)> docs=500000 batch=5000 ./bench.sh wow.tpl
Server: CouchDB/1.2.0a-a68a792-git (Erlang OTP/R14B03)
{"couchdb":"Welcome","version":"1.2.0a-a68a792-git"}
[INFO] Created DB named `db1'
[INFO] Uploaded 5000 documents via _bulk_docs
(....)
[INFO] Uploaded 5000 documents via _bulk_docs
@fdmanana
fdmanana / gist:2160061
Created March 22, 2012 17:17
OS X 64bits release target
From 0a8c3023b5c29463b58d09fc574c5f8f3bd36b99 Mon Sep 17 00:00:00 2001
From: Filipe David Borba Manana <fdmanana@gmail.com>
Date: Fri, 23 Mar 2012 13:48:15 +0000
Subject: [PATCH] Add support for Mac OS X 64bit builds with GYP
Note that in order to build for 64bits mode, you'll have
to specify the target architecture explicitely, the default
is still 32bits for Mac OS X.
Example with make:
From b3895efe1cff61182dfe76fed25c00d6cb590a71 Mon Sep 17 00:00:00 2001
From: Filipe David Borba Manana <fdmanana@apache.org>
Date: Wed, 16 Jan 2013 10:18:36 +0000
Subject: [PATCH] Fix memory leak in efile_drv
When the port's stop callback (file_stop) is invoked, we
schedule a file close task (FILE_CLOSE_ON_PORT_EXIT) that
will be picked up by an async thread, to avoid blocking the
scheduler thread for too long. However, because after this
task is executed the port is not alive anymore, its callback