2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/events/events.h"
25 #include "libcli/cldap/cldap.h"
26 #include "libcli/resolve/resolve.h"
29 int pass_count, fail_count;
32 static void request_handler(struct cldap_request *req)
34 struct cldap_netlogon io;
35 struct bench_state *state = talloc_get_type(req->async.private, struct bench_state);
37 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
39 status = cldap_netlogon_recv(req, tmp_ctx, &io);
40 if (NT_STATUS_IS_OK(status)) {
51 static BOOL bench_cldap(TALLOC_CTX *mem_ctx, const char *address)
53 struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
55 struct timeval tv = timeval_current();
57 int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
58 struct cldap_netlogon search;
59 struct bench_state *state;
61 state = talloc_zero(mem_ctx, struct bench_state);
64 search.in.dest_address = address;
65 search.in.acct_control = -1;
66 search.in.version = 6;
68 printf("Running for %d seconds\n", timelimit);
69 while (timeval_elapsed(&tv) < timelimit) {
70 while (num_sent - (state->pass_count+state->fail_count) < 10) {
71 struct cldap_request *req;
72 req = cldap_netlogon_send(cldap, &search);
74 req->async.private = state;
75 req->async.fn = request_handler;
77 if (num_sent % 50 == 0) {
78 printf("%.1f queries per second (%d failures) \r",
79 state->pass_count / timeval_elapsed(&tv),
84 event_loop_once(cldap->event_ctx);
87 while (num_sent != (state->pass_count + state->fail_count)) {
88 event_loop_once(cldap->event_ctx);
91 printf("%.1f queries per second (%d failures) \n",
92 state->pass_count / timeval_elapsed(&tv),
101 benchmark how fast a CLDAP server can respond to a series of parallel
104 BOOL torture_bench_cldap(void)
107 struct nbt_name name;
108 TALLOC_CTX *mem_ctx = talloc_new(NULL);
112 make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
114 /* do an initial name resolution to find its IP */
115 status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
116 if (!NT_STATUS_IS_OK(status)) {
117 printf("Failed to resolve %s - %s\n",
118 name.name, nt_errstr(status));
119 talloc_free(mem_ctx);
123 ret &= bench_cldap(mem_ctx, address);
125 talloc_free(mem_ctx);