Skip to content

Instantly share code, notes, and snippets.

View aeden's full-sized avatar

Anthony Eden aeden

View GitHub Profile

The limiting factor of erl-dns QPS is in the loop around reading a UDP packet and getting it to a worker, as this is currently executed in a synchronous loop. Workers are asynchronous, so once they have the packet the next UDP packet can be read.

Reading a packet in Erlang is reported to take 10s of microseconds. Casting the packet to the worker takes about 100 microseconds. Getting a worker out of the worker queue is currently the slowest part of the process, taking around 1 millisecond. Originally I was using Poolboy, however pulling workers off the queue was taking 4 to 6 milliseconds.

The approach I am testing now is to have multiple processes reading from the same UDP socket. Under no inbound traffic this strategy does not work too well because there are a lot of ealready errors since the socket is blocking. My current theory is that under high traffic loads these will go away since there will be a constant stream of requests, however it's possible that the number of workers listening to the socket wil

$ erl
Erlang R15B (erts-5.9) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9 (abort with ^G)
1> c(example1).
{ok,example1}
2> example1:sum(10, 20).
30
@aeden
aeden / txt-data-parser.erl
Created November 30, 2012 18:18
A TXT data lexer in Erlang
parse_txt([C|Rest]) -> parse_txt_char([C|Rest], C, Rest, [], false).
parse_txt(String, [], [], _) -> [String];
parse_txt(_, [], Tokens, _) -> Tokens;
parse_txt(String, [C|Rest], Tokens, Escaped) -> parse_txt_char(String, C, Rest, Tokens, Escaped).
parse_txt(String, [C|Rest], Tokens, CurrentToken, Escaped) -> parse_txt_char(String, C, Rest, Tokens, CurrentToken, Escaped).
parse_txt_char(String, $", Rest, Tokens, _) -> parse_txt(String, Rest, Tokens, [], false);
parse_txt_char(String, _, Rest, Tokens, _) -> parse_txt(String, Rest, Tokens, false).
parse_txt_char(String, $", Rest, Tokens, CurrentToken, false) -> parse_txt(String, Rest, Tokens ++ [CurrentToken], false);
parse_txt_char(String, $", Rest, Tokens, CurrentToken, true) -> parse_txt(String, Rest, Tokens, CurrentToken ++ [$"], false);
parse_txt_char(String, $\\, Rest, Tokens, CurrentToken, false) -> parse_txt(String, Rest, Tokens, CurrentToken, true);
@aeden
aeden / travel-challenge-2013.txt
Created October 21, 2012 12:25
The 2013 Travel Challenge
MPL -> NYC 27 Jun 2013
NYC -> SFO 05 Jul 2013
SFO -> HNL 09 Jul 2013
HNL -> MQT 15 Aug 2013
MQT -> MPL 22 Aug 2013
-- Example of using Ratchet to resolve DNS queries
-- Inspect function to print the results:
function inspect(prefix, t)
for k,v in pairs(t) do
if (type(v) == "table") then
inspect(string.format("%s (%s):", prefix, k), v)
else
print(prefix, string.format("%s: %s", k, v))
end
end
@aeden
aeden / running.md
Created May 8, 2012 13:26
Set up for Rails and non-Rails specs playing nicely

You can then execute all specs with:

bundle exec rspec spec

And only run your decoupled tests with:

bundle exec rspec spec --tag ~rails

curl -H "X-DNSimple-Token: EMAIL:API-TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" https://dnsimple.com/domains

To install a JAR into a local maven repo for use in lein:

mkdir maven_repository
mvn install:install-file -Dfile=dnsjava-2.1.3.jar -DartifactId=dnsjava -Dversion=2.1.3 -DgroupId=dnsjava -Dpackaging=jar -DlocalRepositoryPath=maven_repository

Add to project.clj:

:repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}

Get dependencies:

nnoremap .c :!CLASSPATH=lib/* java clojure.main <CR>
/**
* This is example code that shows how you might use the payment form from within
* your application. I've annotated it with comments throughout to clarify its usage.
*/
$(document).ready(function() {
// Construct the payments object, passing in the element that will hold the payment
// form. Here I use a <div> but you could use any type of element.
var credit_card_form = LivingSocial.Payments.CreditCardForm($("#payment-interface"));
// Render the payment form.