Skip to content

Commit 3724809

Browse files
author
zsx
committed
improving some disque samples
1 parent 0efff4d commit 3724809

File tree

10 files changed

+68
-17
lines changed

10 files changed

+68
-17
lines changed

lib_acl_cpp/include/acl_cpp/http/HttpServletResponse.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ACL_CPP_API HttpServletResponse
154154
* 向客户端发送 HTTP 数据体响应数据,可以循环调用此函数,该函数
155155
* 内部调用 HttpServletResponse::write(const void*, size_t) 过程,
156156
* 另外,在使用 chunked 方式传输数据时,应该应该最后再调用一次本函数,
157-
* 且参数均设为 0 表示数据结束
157+
* 且输入空串,即 buf.empty() == true
158158
* @param buf {const string&} 数据缓冲区
159159
* @return {bool} 发送是否成功,如果返回 false 表示连接中断
160160
*/

lib_acl_cpp/samples/disque/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,18 @@ int main(void)
141141
```
142142

143143
### add acl disque to your projects
144-
Before you use the acl disque, you should compile the three base libraries which disque depending on. Enter the lib_acl, lib_protocol, lib_acl_cpp, and build the lib_acl.a, lib_protocol.a and lib_acl_cpp.a.
144+
Before you use the acl disque, you should compile the three base libraries which disque depending on. Enter the ** lib_acl, lib_protocol, lib_acl_cpp,** and build the lib_acl.a, lib_protocol.a and lib_acl_cpp.a.
145+
```compile
145146
$cd lib_acl; make
146147
$cd lib_protocol; make
147148
$cd lib_acl_cpp; make
149+
```
148150

149151
#### On UNIX/LINUX
150152
In your Makefile, you should add below compiling flags:
151153
-DLINUX2 for LINUX, -DFREEBSD for FreeBSD, -DMACOSX for MAXOS, -DSUNOS5 for Solaris X86;
152154
-I path specify the lib_acl.hpp's parent path, for exmaple: -I./lib_acl_cpp/include, in the lib_acl_cpp/include path the acl_cpp path should be included;
153-
At last, link with -L{path_to_acl_cpp} -l_acl_cpp -L{path_to_protocol} -l_protocol -L{path_to_acl) -l_acl
155+
At last, link with ** -L{path_to_acl_cpp} -l_acl_cpp -L{path_to_protocol} -l_protocol -L{path_to_acl) -l_acl **
154156
Of couse you can look at the Makefile.in in lib_acl_cpp\samples and Makfile in lib_acl_cpp\samples\disque\ to find the build conditions.
155157
One Makefile as below:
156158
```Makefile
@@ -169,7 +171,7 @@ main.o: main.cpp
169171
gcc $(CFLAGS) main.cpp -o main.o
170172
```
171173
### On WIN32
172-
Open acl_cpp_vc2003.sln/acl_cpp_vc2008.sln/acl_cpp_vc2010.sln/acl_cpp_vc2012.sln, and looat at the disque samples project option setting.
174+
Open acl_cpp_vc2003.sln/acl_cpp_vc2008.sln/acl_cpp_vc2010.sln/acl_cpp_vc2012.sln, and look at at the disque samples project option setting.
173175

174176
## reference
175177
- disque include in acl: [disque include files](../../include/acl_cpp/disque/)

lib_acl_cpp/samples/disque/disque_client/disque_client.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ static void usage(const char* procname)
271271
"-C [if need ackjob for getjob]\r\n"
272272
"-a cmd[addjob|getjob|qlen|qpeek|show|ackjob|fastack|enqueue|dequeue|deljob|info|hello]\r\n",
273273
procname);
274+
275+
printf("sample:\r\n"
276+
"%s -s 127.0.0.1:7711 -n 10000 -D 1 -R 2 -r 1 -T 1000 -M 1000000 -a addjob\r\n"
277+
"%s -s 127.0.0.1:7711 -n 10000 -a getjob\r\n"
278+
"%s -s 127.0.0.1:7711 -n 10000 -a getjob -C\r\n"
279+
"%s -s 127.0.0.1:7711 -n 10 -a qlen\r\n"
280+
"%s -s 127.0.0.1:7711 -n 100 -a qpeek\r\n"
281+
"%s -s 127.0.0.1:7711 -n 1 -a info\r\n"
282+
"%s -s 127.0.0.1:7711 -n 1 -a hello\r\n",
283+
procname, procname, procname, procname, procname, procname, procname);
274284
}
275285

276286
int main(int argc, char* argv[])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
valgrind --tool=memcheck --leak-check=yes -v ./disque_client -s 127.0.0.1:7711 -a all -n 10
3+
valgrind --tool=memcheck --leak-check=yes -v ./disque_client -s 127.0.0.1:7711 -a addjob -n 10000

lib_acl_cpp/samples/disque/disque_cluster/disque_cluster.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ static void usage(const char* procname)
196196
"-A [async]\r\n"
197197
"-a cmd[addjob|getjob|qlen|qpeek]\r\n",
198198
procname);
199+
200+
printf("sample:\r\n"
201+
"%s -s \"127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713\" -n 10000 -c 10 -D 1 -R 2 -M 1000000 -A -a addjob\r\n"
202+
"%s -s \"127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713\" -n 10000 -c 10 -a getjob\r\n"
203+
"%s -s \"127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713\" -n 1 -c 10 -a qlen\r\n"
204+
"%s -s \"127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713\" -n 1 -c 10 -a qpeek\r\n",
205+
procname, procname, procname, procname);
199206
}
200207

201208
int main(int argc, char* argv[])

lib_acl_cpp/samples/disque/disque_manager/disque_manager.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class test_thread : public acl::thread
195195
static void usage(const char* procname)
196196
{
197197
printf("usage: %s -h[help]\r\n"
198-
"-s redis_addr[127.0.0.1:6379]\r\n"
198+
"-s redis_addr_list[127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713]\r\n"
199199
"-n count[default: 10]\r\n"
200200
"-C connect_timeout[default: 10]\r\n"
201201
"-I rw_timeout[default: 10]\r\n"
@@ -208,14 +208,21 @@ static void usage(const char* procname)
208208
"-A [async]\r\n"
209209
"-a cmd[addjob|getjob|qlen|qpeek]\r\n",
210210
procname);
211+
212+
printf("sample:\r\n"
213+
"%s -s \"127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713\" -n 10000 -c 10 -D 1 -R 2 -M 1000000 -A -a addjob\r\n"
214+
"%s -s \"127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713\" -n 10000 -c 10 -a getjob\r\n"
215+
"%s -s \"127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713\" -n 1 -c 10 -a qlen\r\n"
216+
"%s -s \"127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713\" -n 1 -c 10 -a qpeek\r\n",
217+
procname, procname, procname, procname);
211218
}
212219

213220
int main(int argc, char* argv[])
214221
{
215222
int ch, n = 1, conn_timeout = 10, rw_timeout = 10;
216223
int max_threads = 10;
217224
acl::disque_cond cond;
218-
acl::string addr("127.0.0.1:6379"), cmd;
225+
acl::string addr_list("127.0.0.1:7711, 127.0.0.1:7712, 127.0.0.1:7713"), cmd;
219226

220227
while ((ch = getopt(argc, argv, "hs:n:C:I:c:a:D:R:r:T:M:A")) > 0)
221228
{
@@ -225,7 +232,7 @@ int main(int argc, char* argv[])
225232
usage(argv[0]);
226233
return 0;
227234
case 's':
228-
addr = optarg;
235+
addr_list = optarg;
229236
break;
230237
case 'n':
231238
n = atoi(optarg);
@@ -267,8 +274,18 @@ int main(int argc, char* argv[])
267274

268275
acl::acl_cpp_init();
269276

277+
if (addr_list.empty())
278+
{
279+
usage(argv[0]);
280+
return 1;
281+
}
282+
270283
acl::disque_client_cluster manager(conn_timeout, rw_timeout);
271-
manager.set(addr.c_str(), max_threads);
284+
const std::vector<acl::string>& tokens = addr_list.split2(";, \t");
285+
286+
std::vector<acl::string>::const_iterator cit;
287+
for (cit = tokens.begin(); cit != tokens.end(); ++cit)
288+
manager.set((*cit).c_str(), max_threads);
272289

273290
std::vector<test_thread*> threads;
274291
for (int i = 0; i < max_threads; i++)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
valgrind --tool=memcheck --leak-check=yes -v ./disque_manager -s 127.0.0.1:7711 -a all -n 10 -c 10
3+
valgrind --tool=memcheck --leak-check=yes -v ./disque_manager -s 127.0.0.1:7711 -a addjob -n 10 -c 10

lib_acl_cpp/samples/disque/disque_pool/disque_pool.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,26 @@ class test_thread : public acl::thread
186186
static void usage(const char* procname)
187187
{
188188
printf("usage: %s -h[help]\r\n"
189-
"-s redis_addr[127.0.0.1:6379]\r\n"
189+
"-s redis_addr[127.0.0.1:7711]\r\n"
190190
"-n count[default: 10]\r\n"
191191
"-C connect_timeout[default: 10]\r\n"
192192
"-I rw_timeout[default: 10]\r\n"
193193
"-c max_threads[default: 10]\r\n"
194+
"-D delay\r\n"
195+
"-R replicate\r\n"
196+
"-r retry\r\n"
197+
"-T ttl\r\n"
198+
"-M maxlen\r\n"
199+
"-A [async]\r\n"
194200
"-a cmd[addjob|getjob|qlen|qpeek]\r\n",
195201
procname);
202+
203+
printf("sample:\r\n"
204+
"%s -s 127.0.0.1:7711 -n 10000 -c 10 -D 1 -R 2 -M 1000000 -A -a addjob\r\n"
205+
"%s -s 127.0.0.1:7711 -n 10000 -c 10 -a getjob\r\n"
206+
"%s -s 127.0.0.1:7711 -n 1 -c 10 -a qlen\r\n"
207+
"%s -s 127.0.0.1:7711 -n 1 -c 10 -a qpeek\r\n",
208+
procname, procname, procname, procname);
196209
}
197210

198211
int main(int argc, char* argv[])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
valgrind --tool=memcheck --leak-check=yes -v ./disque_pool -s 127.0.0.1:7711 -a all -n 10 -c 10
3+
valgrind --tool=memcheck --leak-check=yes -v ./disque_pool -s 127.0.0.1:7711 -a addjob -n 10 -c 10

lib_acl_cpp/samples/redis/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ The header files of acl redis are in lib_acl_cpp\include\acl_cpp\redis; the sour
88
Because acl redis lib is a part of lib_acl_cpp lib, and lib_acl_cpp depend lib_acl and lib_protocol, you should compile lib_acl and lib_protocol libs first, and compile lib_acl_cpp lib. After you've compiled lib_acl_cpp lib, the redis lib is also compiled OK.
99

1010
### compile on UNIX/LINUX
11-
- 1 compile lib_acl.a: Enter into lib_acl path and type make, the lib_acl.a will be compiled
12-
- 2 compile lib_protocol.a: Enter into lib_protocol path and type make, the lib_protocol.a will be compiled
13-
- 3 compile lib_acl_cpp.a: Enter into lib_acl_cpp path and type make, the lib_acl_cpp.a will be compiled
11+
- 1 compile ** lib_acl.a **: Enter into lib_acl path and type make, the lib_acl.a will be compiled
12+
- 2 compile ** lib_protocol.a **: Enter into lib_protocol path and type make, the lib_protocol.a will be compiled
13+
- 3 compile ** lib_acl_cpp.a **: Enter into lib_acl_cpp path and type make, the lib_acl_cpp.a will be compiled
1414
- 4 compile redis samples: Enter into lib_acl_cpp\samples\redis and type make, all the redis samples(including redis_cluster, redis_connection, redis_hash, redis_hyperloglog, redis_key, redis_lib, redis_manager, redis_pool, redis_pubsub, redis_server, redis_set, redis_string, redis_trans, redis_zset, redis_zset_pool, redis_client_cluster) will be compiled.
1515

1616
### compile on WINDOWS
@@ -214,10 +214,12 @@ int main(void)
214214
```
215215

216216
### add acl redis to your projects
217-
Before you use the acl redis, you should compile the three base libraries which redis depending on. Enter the lib_acl, lib_protocol, lib_acl_cpp, and build the lib_acl.a, lib_protocol.a and lib_acl_cpp.a.
217+
Before you use the acl redis, you should compile the three base libraries which redis depending on. Enter the lib_acl, lib_protocol, lib_acl_cpp, and build the ** lib_acl.a, lib_protocol.a and lib_acl_cpp.a **.
218+
```compile
218219
$cd lib_acl; make
219220
$cd lib_protocol; make
220221
$cd lib_acl_cpp; make
222+
```
221223

222224
#### On UNIX/LINUX
223225
In your Makefile, you should add below compiling flags:
@@ -242,7 +244,7 @@ main.o: main.cpp
242244
gcc $(CFLAGS) main.cpp -o main.o
243245
```
244246
### On WIN32
245-
Open acl_cpp_vc2003.sln/acl_cpp_vc2008.sln/acl_cpp_vc2010.sln/acl_cpp_vc2012.sln, and looat at the redis samples project option setting.
247+
Open acl_cpp_vc2003.sln/acl_cpp_vc2008.sln/acl_cpp_vc2010.sln/acl_cpp_vc2012.sln, and look at at the redis samples project option setting.
246248

247249
## reference
248250
- redis include in acl: [redis include files](../../include/acl_cpp/redis/)

0 commit comments

Comments
 (0)