Skip to content

Commit

Permalink
feat: Remote interface interoperate distributed computing resources
Browse files Browse the repository at this point in the history
* make BUILD_REMOTE=1 to build libdcurl.so and remote-worker
* make BUILD_REMOTE=1 check with RabbitMQ broker and remote-worker
* RPC with exclusive callback queues with TTL property
* AMQP connection management for multiple threads
* Implement local fallback PoW when remote interface fails

Related #137
  • Loading branch information
ajblane committed May 31, 2019
1 parent f2c5292 commit 88a5cb6
Show file tree
Hide file tree
Showing 12 changed files with 862 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "deps/libtuv"]
path = deps/libtuv
url = https://github.com/DLTcollab/libtuv.git
[submodule "deps/rabbitmq-c"]
path = deps/rabbitmq-c
url = https://github.com/alanxz/rabbitmq-c.git
32 changes: 26 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ ifeq ("$(BUILD_FPGA_ACCEL)","1")
CFLAGS += -DENABLE_FPGA_ACCEL
endif

ifeq ("$(BUILD_REMOTE)","1")
CFLAGS += -DENABLE_REMOTE
endif

ifeq ("$(BUILD_JNI)","1")
include mk/java.mk
endif
Expand Down Expand Up @@ -99,6 +103,9 @@ PREQ := config $(TESTS) $(LIBS)
ifeq ("$(BUILD_JNI)","1")
PREQ += $(JARS)
endif
ifeq ("$(BUILD_REMOTE)", "1")
PREQ += $(OUT)/remote-worker
endif

all: $(PREQ)
.DEFAULT_GOAL := all
Expand Down Expand Up @@ -140,23 +147,36 @@ OBJS += \
pow_fpga_accel.o
endif

ifeq ("$(BUILD_REMOTE)", "1")
OBJS += \
remote_common.o \
remote_interface.o

WORKER_OBJS := $(addprefix $(OUT)/worker-,$(filter-out remote_interface.o, $(OBJS)))
WORKER_CFLAGS := $(filter-out -DENABLE_REMOTE, $(CFLAGS))
endif

OBJS := $(addprefix $(OUT)/, $(OBJS))

$(OUT)/test-%.o: tests/test-%.c $(LIBTUV_PATH)/include
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -I $(SRC) $(LIBTUV_INCLUDE) -c -MMD -MF $@.d $<

$(OUT)/%.o: $(SRC)/%.c $(LIBTUV_PATH)/include
$(OUT)/%.o: $(SRC)/%.c $(LIBTUV_PATH)/include $(LIBRABBITMQ_PATH)/build/include
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) $(LIBTUV_INCLUDE) -c -MMD -MF $@.d $<
$(Q)$(CC) -o $@ $(CFLAGS) $(LIBTUV_INCLUDE) $(LIBRABBITMQ_INCLUDE) -c -MMD -MF $@.d $<

$(OUT)/test-%: $(OUT)/test-%.o $(OBJS) $(LIBTUV_LIBRARY)
$(OUT)/test-%: $(OUT)/test-%.o $(OBJS) $(LIBTUV_LIBRARY) $(LIBRABBITMQ_LIBRARY)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)
$(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBRABBITMQ_LINK)

$(OUT)/libdcurl.so: $(OBJS) $(LIBTUV_LIBRARY)
$(OUT)/libdcurl.so: $(OBJS) $(LIBTUV_LIBRARY) $(LIBRABBITMQ_LIBRARY)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -shared -o $@ $^ $(LDFLAGS)
$(Q)$(CC) -shared -o $@ $^ $(LDFLAGS) $(LIBRABBITMQ_LINK)

ifeq ("$(BUILD_REMOTE)", "1")
include mk/remote.mk
endif

include mk/common.mk

Expand Down
1 change: 1 addition & 0 deletions deps/rabbitmq-c
Submodule rabbitmq-c added at 75a21e
3 changes: 3 additions & 0 deletions mk/defs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ BUILD_GPU ?= 0
# Build FPGA backend or not
BUILD_FPGA_ACCEL ?= 0

# Build facilities of remote procedure calls
BUILD_REMOTE ?= 0

# Build JNI glue as the bridge between dcurl and IRI
BUILD_JNI ?= 0

Expand Down
8 changes: 8 additions & 0 deletions mk/remote.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Build remote-worker
$(OUT)/worker-%.o: $(SRC)/%.c $(LIBTUV_PATH)/include $(LIBRABBITMQ_PATH)/build/include
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(WORKER_CFLAGS) $(LIBTUV_INCLUDE) $(LIBRABBITMQ_INCLUDE) -c -MMD -MF $@.d $<

$(OUT)/remote-worker: $(OUT)/remote_worker.o $(WORKER_OBJS) $(LIBTUV_LIBRARY) $(LIBRABBITMQ_LIBRARY)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBRABBITMQ_LINK)
31 changes: 31 additions & 0 deletions mk/submodule.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,34 @@ $(LIBTUV_PATH)/include:

$(LIBTUV_LIBRARY):
$(MAKE) -C $(LIBTUV_PATH) TUV_BUILD_TYPE=release TUV_CREATE_PIC_LIB=yes TUV_PLATFORM=$(LIBTUV_PLATFORM) TUV_BOARD=$(LIBTUV_BOARD)

# librabbitmq related variables
LIBRABBITMQ_PATH = deps/rabbitmq-c
LIBRABBITMQ_INCLUDE := -I $(LIBRABBITMQ_PATH)/build/include
LIBRABBITMQ_LIB_PATH := $(LIBRABBITMQ_PATH)/build/librabbitmq/
ifeq ($(UNAME_S),darwin)
# macOS
LIBRABBITMQ_LINK := -Wl,-rpath,$(LIBRABBITMQ_LIB_PATH) -L$(LIBRABBITMQ_LIB_PATH) -lrabbitmq
LIBRABBITMQ_LIBRARY := $(LIBRABBITMQ_LIB_PATH)/librabbitmq.dylib
else
LIBRABBITMQ_LINK := -Wl,-rpath=$(LIBRABBITMQ_LIB_PATH) -L$(LIBRABBITMQ_LIB_PATH) -lrabbitmq
LIBRABBITMQ_LIBRARY := $(LIBRABBITMQ_LIB_PATH)/librabbitmq.so
endif

$(LIBRABBITMQ_PATH)/build/include:
git submodule update --init $(LIBRABBITMQ_PATH)
mkdir $(LIBRABBITMQ_PATH)/build
ifeq ($(UNAME_S),darwin)
# macOS
cd $(LIBRABBITMQ_PATH)/build && \
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DCMAKE_INSTALL_PREFIX=. .. && \
cmake --build . --target install
else
cd $(LIBRABBITMQ_PATH)/build && \
cmake -DCMAKE_INSTALL_PREFIX=. .. && \
cmake --build . --target install
endif

$(LIBRABBITMQ_LIBRARY):
cd $(LIBRABBITMQ_PATH)/build && \
cmake --build .
39 changes: 39 additions & 0 deletions src/dcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#if defined(ENABLE_FPGA_ACCEL)
#include "pow_fpga_accel.h"
#endif
#if defined(ENABLE_REMOTE)
#include "remote_interface.h"
#endif
#include "implcontext.h"
#include "trinary.h"
#include "uv.h"
Expand Down Expand Up @@ -48,6 +51,11 @@ extern ImplContext PoWCL_Context;
extern ImplContext PoWFPGAAccel_Context;
#endif

#if defined(ENABLE_REMOTE)
extern RemoteImplContext Remote_Context;
static uv_sem_t notify_remote;
#endif

bool dcurl_init()
{
bool ret = true;
Expand All @@ -68,6 +76,11 @@ bool dcurl_init()
ret &= registerImplContext(&PoWFPGAAccel_Context);
#endif

#if defined(ENABLE_REMOTE)
ret &= initializeRemoteContext(&Remote_Context);
uv_sem_init(&notify_remote, 0);
#endif

uv_sem_init(&notify, 0);
return isInitialized = ret;
}
Expand All @@ -77,6 +90,10 @@ void dcurl_destroy()
ImplContext *impl = NULL;
struct list_head *p;

#if defined(ENABLE_REMOTE)
destroyRemoteContext(&Remote_Context);
#endif

list_for_each (p, &IMPL_LIST) {
impl = list_entry(p, ImplContext, list);
destroyImplContext(impl);
Expand All @@ -96,6 +113,28 @@ int8_t *dcurl_entry(int8_t *trytes, int mwm, int threads)
if (!isInitialized)
return NULL;

#if defined(ENABLE_REMOTE)
do {
if (enterRemoteContext(&Remote_Context)) {
pow_ctx = getRemoteContext(&Remote_Context, trytes, mwm);
goto remote_pow;
}
uv_sem_wait(&notify_remote);
} while (1);

remote_pow:
if (!doRemoteContext(&Remote_Context, pow_ctx)) {
goto local_pow;
} else {
res = getRemoteResult(&Remote_Context, pow_ctx);
}
freeRemoteContext(&Remote_Context, pow_ctx);
exitRemoteContext(&Remote_Context);
uv_sem_post(&notify_remote);
return res;

local_pow:
#endif
do {
list_for_each (p, &IMPL_LIST) {
impl = list_entry(p, ImplContext, list);
Expand Down
Loading

0 comments on commit 88a5cb6

Please sign in to comment.