Skip to content

Instantly share code, notes, and snippets.

View JoshuaChi's full-sized avatar

Joshua Chi JoshuaChi

View GitHub Profile
@JoshuaChi
JoshuaChi / CAS spin lock
Created December 11, 2014 02:12
CAS spin lock
https://github.com/cloudwu/skynet/pull/208/files
diff --git a/skynet-src/skynet_mq.c b/skynet-src/skynet_mq.c
index 8cc8f9d..51f47ef 100644
--- a/skynet-src/skynet_mq.c
+++ b/skynet-src/skynet_mq.c
@@ -32,12 +32,9 @@ struct message_queue {
};
struct global_queue {
%% Description: A simple FSM for a code lock with three states
%% based on an example from the OTP system documentation
-module(code_lock_fsm).
-behaviour(gen_fsm).
%% public API functions
-export([start_link/1, stop/0, button/1, reset/0, get_state/0]).
%% state names
-export([locked/2, locked/3, open/2, open/3]).
@JoshuaChi
JoshuaChi / system_monitor
Created August 21, 2014 01:59
get_busy_dist_port
%% Copyright (c) 2011 Basho Technologies, Inc. All Rights Reserved.
%%
%% 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,
# set up flags for Numpy C extentions compiling
export CFLAGS="-arch i386 -arch x86_64"
export FFLAGS="-m32 -m64"
export LDFLAGS="-Wall -undefined dynamic_lookup -bundle -arch i386 -arch x86_64"
export CC=gcc-4.2
export CXX="g++ -arch i386 -arch x86_64"
pip install numpy
# success!
#!/bin/sh
#
# Usage: ./redis-delkeys.sh [-h host] [-p port] [-n db] pattern
#
# Matches keys with the KEYS command matching pattern
# and deletes them from the specified Redis DB.
set -e
HOST="localhost"
@JoshuaChi
JoshuaChi / erlang_gc
Last active August 29, 2015 14:00
Manually GC
[erlang:garbage_collect(Pid) || Pid <- processes()].
If you want, I can try and help with pointers as to how to improve the indexing speed you get. Its quite easy to really increase it by using some simple guidelines, for example:
- Use create in the index API (assuming you can).
- Relax the real time aspect from 1 second to something a bit higher (index.engine.robin.refresh_interval).
- Increase the indexing buffer size (indices.memory.index_buffer_size), it defaults to the value 10% which is 10% of the heap.
- Increase the number of dirty operations that trigger automatic flush (so the translog won't get really big, even though its FS based) by setting index.translog.flush_threshold (defaults to 5000).
- Increase the memory allocated to elasticsearch node. By default its 1g.
- Start with a lower replica count (even 0), and then once the bulk loading is done, increate it to the value you want it to be using the update_settings API. This will improve things as possibly less shards will be allocated to each machine.
- Increase the number of machines you have so
curl -XDELETE http://localhost:9200/ac-test
curl -XPUT http://localhost:9200/ac-test
curl -XPUT http://localhost:9200/ac-test/people/1 -d '
{
"firstNames" : "James Earl",
"lastName" : "Jones",
"location" : "Hollywood, CA"
}'
curl -XPUT http://localhost:9200/ac-test/people/2 -d '
@JoshuaChi
JoshuaChi / binary replace
Last active December 31, 2015 22:19
binary replace takes too long to execute
byte_size(V).
599833
binary:replace(V, <<0>>, <<>>, [global]).
binary:part(V,{10, 1000}).
def bits(n):
    while n:
        b = n & (~n+1)
        yield b
        n ^= b
>>> for b in bits(109):
    print(b)