Permalink
Browse files

do not use syscall-based timers but rely on libev embedded cached one

  • Loading branch information...
Roberto De Ioris
Roberto De Ioris committed Aug 18, 2012
1 parent 176d2ce commit 698375889f977cfc314f53d2d599053179e928f4
Showing with 11 additions and 9 deletions.
  1. +4 −2 blastbeat.h
  2. +3 −3 src/main.c
  3. +4 −4 src/zmq.c
View
@@ -40,6 +40,8 @@
#define ntohll(y) (((uint64_t)ntohl(y)) << 32 | ntohl(y>>32))
#define htonll(y) (((uint64_t)htonl(y)) << 32 | htonl(y>>32))
#define bb_now round(ev_now(blastbeat.loop));
#define BB_UUID_LEN 16
// flags for the writequeue
@@ -67,7 +69,7 @@ struct bb_session;
struct bb_dealer {
char *identity;
size_t len;
time_t last_seen;
ev_tstamp last_seen;
int status;
int spawn_sent;
uint64_t load;
@@ -372,7 +374,7 @@ struct bb_session {
struct bb_virtualhost *vhost;
// used for monitoring inactivity
time_t last_seen;
ev_tstamp last_seen;
// persistent sessions can be re-called (useful for socket.io in xhr-polling)
int persistent;
View
@@ -426,10 +426,10 @@ static void pinger_cb(struct ev_loop *loop, struct ev_timer *w, int revents) {
struct bb_dealer *bbd = blastbeat.dealers;
// get events before starting a potentially long write session
ev_feed_event(blastbeat.loop, &blastbeat.event_zmq, EV_READ);
time_t now = time(NULL);
ev_tstamp now = bb_now;
while(bbd) {
time_t delta = now - bbd->last_seen;
if (delta > blastbeat.ping_freq) {
ev_tstamp delta = now - bbd->last_seen;
if (delta >= blastbeat.ping_freq) {
if (delta > (blastbeat.ping_freq * 3) && bbd->status == BLASTBEAT_DEALER_AVAILABLE) {
bbd->status = BLASTBEAT_DEALER_OFF;
fprintf(stderr,"node \"%s\" is OFF\n", bbd->identity);
View
@@ -92,8 +92,8 @@ void bb_zmq_send_msg(struct bb_session *bbs, char *identity, size_t identity_len
static void update_dealer(struct bb_dealer *bbd, time_t now) {
bbd->last_seen = now;
static void update_dealer(struct bb_dealer *bbd, ev_tstamp now) {
bbd->last_seen = bb_now;
if (bbd->status == BLASTBEAT_DEALER_OFF) {
bbd->status = BLASTBEAT_DEALER_AVAILABLE;
fprintf(stderr, "node \"%s\" is available\n", bbd->identity);
@@ -102,7 +102,7 @@ static void update_dealer(struct bb_dealer *bbd, time_t now) {
static void manage_ping(char *identity, size_t len) {
struct bb_dealer *bbd = blastbeat.dealers;
time_t now = time(NULL);
ev_tstamp now = bb_now;
while(bbd) {
if (!bb_strcmp(identity, len, bbd->identity, bbd->len)) {
update_dealer(bbd, now);
@@ -157,7 +157,7 @@ void bb_zmq_receiver(struct ev_loop *loop, struct ev_io *w, int revents) {
struct bb_session *bbs = bb_sht_get(zmq_msg_data(&msg[1]));
if (!bbs) goto next;
time_t now = time(NULL);
ev_tstamp now = bb_now;
bbs->last_seen = now;
update_dealer(bbs->dealer, now);

0 comments on commit 6983758

Please sign in to comment.