2 * $Id: heavy.c,v 1.3 2005/04/25 16:42:24 paul Exp $
4 * This file is part of Quagga.
6 * Quagga is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * Quagga is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Quagga; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This programme shows the effects of 'heavy' long-running functions
23 * on the cooperative threading model.
25 * Run it with a config file containing 'password whatever', telnet to it
26 * (it defaults to port 4000) and enter the 'clear foo string' command.
27 * then type whatever and observe that the vty interface is unresponsive
28 * for quite a period of time, due to the clear_something command
29 * taking a very long time to complete.
49 slow_func (struct vty
*vty
, const char *str
, const int i
)
54 for (j
= 0; j
< 300; j
++)
57 if ((i
% ITERS_LATER
) == 0)
58 printf ("%s: %d, temporary error, save this somehow and do it later..\n",
61 if ((i
% ITERS_ERR
) == 0)
62 printf ("%s: hard error\n", __func__
);
64 if ((i
% ITERS_PRINT
) == 0)
65 printf ("%s did %d, x = %g%s", str
, i
, x
, VTY_NEWLINE
);
69 clear_something (struct vty
*vty
, const char *str
)
73 /* this could be like iterating through 150k of route_table
74 * or worse, iterating through a list of peers, to bgp_stop them with
75 * each having 150k route tables to process...
77 for (i
= ITERS_FIRST
; i
< ITERS_MAX
; i
++)
78 slow_func (vty
, str
, i
);
90 vty_out (vty
, "%% string argument required%s", VTY_NEWLINE
);
94 str
= argv_concat (argv
, argc
, 0);
96 clear_something (vty
, str
);
97 XFREE (MTYPE_TMP
, str
);
104 install_element (VIEW_NODE
, &clear_foo_cmd
);