MCPcopy Create free account
hub / github.com/acl-dev/acl / consumer

Function consumer

lib_acl_cpp/samples/beanstalk/beanstalk.cpp:48–97  ·  view source on GitHub ↗

���ն�����Ϣ���������߳�

Source from the content-addressed store, hash-verified

46
47// ���ն�����Ϣ���������߳�
48static void* consumer(void* ctx)
49{
50 (void) ctx;
51
52 acl::beanstalk conn(__addr, 10);
53 // ��ָ����Ϣ�����н�����Ϣ
54 if (conn.watch(__tube) == false)
55 {
56 printf("%s: watch %s faile\r\n", __FUNCTION__, __tube);
57 return NULL;
58 }
59
60 acl::string buf;
61 unsigned long long id;
62 struct timeval begin, end;
63 gettimeofday(&begin, NULL);
64 ACL_METER_TIME("begin");
65 for (int i = 0; i < __max; i++)
66 {
67 // ����һ����Ϣ
68 if ((id = conn.reserve(buf)) == 0)
69 {
70 printf("reserve failed\r\n");
71 return NULL;
72 }
73 else if (i < 10)
74 printf("reserved: %s\r\n", buf.c_str());
75
76 // ɾ�����յ�����Ϣ
77 if (conn.delete_id(id) == false)
78 {
79 printf("delete id %llu failed\r\n", id);
80 return NULL;
81 }
82 else if (i < 10)
83 printf("delete id %llu ok\r\n", id);
84 if (i % 1000 == 0)
85 {
86 buf.format_append("; total: %d, curr: %d, id: %lld",
87 __max, i, id);
88 ACL_METER_TIME(buf.c_str());
89 }
90 }
91
92 gettimeofday(&end, NULL);
93 double n = util::stamp_sub(&end, &begin);
94 printf("total get: %d, spent: %0.2f ms, speed: %0.2f\r\n",
95 __max, n, (__max * 1000) /(n > 0 ? n : 1));
96 return NULL;
97}
98
99static void test1()
100{

Callers

nothing calls this directly

Calls 6

delete_idMethod · 0.80
gettimeofdayFunction · 0.50
stamp_subFunction · 0.50
watchMethod · 0.45
reserveMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…