1
/* $Id: tsx_bench.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#define THIS_FILE "tsx_uas_test.c"
27
static pjsip_module mod_tsx_user;
29
static int uac_tsx_bench(unsigned working_set, pj_timestamp *p_elapsed)
32
pjsip_tx_data *request;
33
pjsip_transaction **tsx;
34
pj_timestamp t1, t2, elapsed;
38
/* Create the request first. */
39
pj_str_t str_target = pj_str("sip:someuser@someprovider.com");
40
pj_str_t str_from = pj_str("\"Local User\" <sip:localuser@serviceprovider.com>");
41
pj_str_t str_to = pj_str("\"Remote User\" <sip:remoteuser@serviceprovider.com>");
42
pj_str_t str_contact = str_from;
44
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method,
45
&str_target, &str_from, &str_to,
46
&str_contact, NULL, -1, NULL,
48
if (status != PJ_SUCCESS) {
49
app_perror(" error: unable to create request", status);
53
via = (pjsip_via_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_VIA,
56
/* Create transaction array */
57
tsx = (pjsip_transaction**) pj_pool_zalloc(request->pool, working_set * sizeof(pj_pool_t*));
59
pj_bzero(&mod_tsx_user, sizeof(mod_tsx_user));
64
pj_get_timestamp(&t1);
65
for (i=0; i<working_set; ++i) {
66
status = pjsip_tsx_create_uac(&mod_tsx_user, request, &tsx[i]);
67
if (status != PJ_SUCCESS)
69
/* Reset branch param */
70
via->branch_param.slen = 0;
72
pj_get_timestamp(&t2);
73
pj_sub_timestamp(&t2, &t1);
74
pj_add_timestamp(&elapsed, &t2);
76
p_elapsed->u64 = elapsed.u64;
80
for (i=0; i<working_set; ++i) {
82
pjsip_tsx_terminate(tsx[i], 601);
86
pjsip_tx_data_dec_ref(request);
93
static int uas_tsx_bench(unsigned working_set, pj_timestamp *p_elapsed)
96
pjsip_tx_data *request;
99
pj_sockaddr_in remote;
100
pjsip_transaction **tsx;
101
pj_timestamp t1, t2, elapsed;
102
char branch_buf[80] = PJSIP_RFC3261_BRANCH_ID "0000000000";
105
/* Create the request first. */
106
pj_str_t str_target = pj_str("sip:someuser@someprovider.com");
107
pj_str_t str_from = pj_str("\"Local User\" <sip:localuser@serviceprovider.com>");
108
pj_str_t str_to = pj_str("\"Remote User\" <sip:remoteuser@serviceprovider.com>");
109
pj_str_t str_contact = str_from;
111
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method,
112
&str_target, &str_from, &str_to,
113
&str_contact, NULL, -1, NULL,
115
if (status != PJ_SUCCESS) {
116
app_perror(" error: unable to create request", status);
121
via = pjsip_via_hdr_create(request->pool);
122
via->sent_by.host = pj_str("192.168.0.7");
123
via->sent_by.port = 5061;
124
via->transport = pj_str("udp");
125
via->rport_param = 1;
126
via->recvd_param = pj_str("192.168.0.7");
127
pjsip_msg_insert_first_hdr(request->msg, (pjsip_hdr*)via);
130
/* Create "dummy" rdata from the tdata */
131
pj_bzero(&rdata, sizeof(pjsip_rx_data));
132
rdata.tp_info.pool = request->pool;
133
rdata.msg_info.msg = request->msg;
134
rdata.msg_info.from = (pjsip_from_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL);
135
rdata.msg_info.to = (pjsip_to_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_TO, NULL);
136
rdata.msg_info.cseq = (pjsip_cseq_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_CSEQ, NULL);
137
rdata.msg_info.cid = (pjsip_cid_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL);
138
rdata.msg_info.via = via;
140
pj_sockaddr_in_init(&remote, 0, 0);
141
status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_LOOP_DGRAM,
142
&remote, sizeof(pj_sockaddr_in),
143
NULL, &rdata.tp_info.transport);
144
if (status != PJ_SUCCESS) {
145
app_perror(" error: unable to get loop transport", status);
150
/* Create transaction array */
151
tsx = (pjsip_transaction**) pj_pool_zalloc(request->pool, working_set * sizeof(pj_pool_t*));
153
pj_bzero(&mod_tsx_user, sizeof(mod_tsx_user));
154
mod_tsx_user.id = -1;
159
pj_get_timestamp(&t1);
160
for (i=0; i<working_set; ++i) {
161
via->branch_param.ptr = branch_buf;
162
via->branch_param.slen = PJSIP_RFC3261_BRANCH_LEN +
163
pj_ansi_sprintf(branch_buf+PJSIP_RFC3261_BRANCH_LEN,
165
status = pjsip_tsx_create_uas(&mod_tsx_user, &rdata, &tsx[i]);
166
if (status != PJ_SUCCESS)
170
pj_get_timestamp(&t2);
171
pj_sub_timestamp(&t2, &t1);
172
pj_add_timestamp(&elapsed, &t2);
174
p_elapsed->u64 = elapsed.u64;
178
for (i=0; i<working_set; ++i) {
180
pjsip_tsx_terminate(tsx[i], 601);
184
pjsip_tx_data_dec_ref(request);
193
enum { WORKING_SET=10000, REPEAT = 4 };
195
pj_timestamp usec[REPEAT], min, freq;
199
status = pj_get_timestamp_freq(&freq);
200
if (status != PJ_SUCCESS)
207
PJ_LOG(3,(THIS_FILE, " benchmarking UAC transaction creation:"));
208
for (i=0; i<REPEAT; ++i) {
209
PJ_LOG(3,(THIS_FILE, " test %d of %d..",
211
status = uac_tsx_bench(WORKING_SET, &usec[i]);
212
if (status != PJ_SUCCESS)
216
min.u64 = PJ_UINT64(0xFFFFFFFFFFFFFFF);
217
for (i=0; i<REPEAT; ++i) {
218
if (usec[i].u64 < min.u64) min.u64 = usec[i].u64;
223
pj_ansi_sprintf(desc, "Time to create %d UAC transactions, in miliseconds",
225
report_ival("create-uac-time", (unsigned)(min.u64 * 1000 / freq.u64), "msec", desc);
229
speed = (unsigned)(freq.u64 * WORKING_SET / min.u64);
230
PJ_LOG(3,(THIS_FILE, " UAC created at %d tsx/sec", speed));
232
pj_ansi_sprintf(desc, "Number of UAC transactions that potentially can be created per second "
233
"with <tt>pjsip_tsx_create_uac()</tt>, based on the time "
234
"to create %d simultaneous transactions above.",
237
report_ival("create-uac-tsx-per-sec",
238
speed, "tsx/sec", desc);
245
PJ_LOG(3,(THIS_FILE, " benchmarking UAS transaction creation:"));
246
for (i=0; i<REPEAT; ++i) {
247
PJ_LOG(3,(THIS_FILE, " test %d of %d..",
249
status = uas_tsx_bench(WORKING_SET, &usec[i]);
250
if (status != PJ_SUCCESS)
254
min.u64 = PJ_UINT64(0xFFFFFFFFFFFFFFF);
255
for (i=0; i<REPEAT; ++i) {
256
if (usec[i].u64 < min.u64) min.u64 = usec[i].u64;
261
pj_ansi_sprintf(desc, "Time to create %d UAS transactions, in miliseconds",
263
report_ival("create-uas-time", (unsigned)(min.u64 * 1000 / freq.u64), "msec", desc);
267
speed = (unsigned)(freq.u64 * WORKING_SET / min.u64);
268
PJ_LOG(3,(THIS_FILE, " UAS created at %d tsx/sec", speed));
270
pj_ansi_sprintf(desc, "Number of UAS transactions that potentially can be created per second "
271
"with <tt>pjsip_tsx_create_uas()</tt>, based on the time "
272
"to create %d simultaneous transactions above.",
275
report_ival("create-uas-tsx-per-sec",
276
speed, "tsx/sec", desc);