benchmark-million-async.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include "task.h"
23 #include "uv.h"
24 
26  unsigned async_events;
27  unsigned handles_seen;
28  uv_async_t async_handles[1024 * 1024];
29 };
30 
31 static volatile int done;
33 static struct async_container* container;
34 
35 
36 static unsigned fastrand(void) {
37  static unsigned g = 0;
38  g = g * 214013 + 2531011;
39  return g;
40 }
41 
42 
43 static void thread_cb(void* arg) {
44  unsigned i;
45 
46  while (done == 0) {
49  }
50 }
51 
52 
53 static void async_cb(uv_async_t* handle) {
55  handle->data = handle;
56 }
57 
58 
59 static void timer_cb(uv_timer_t* handle) {
60  unsigned i;
61 
62  done = 1;
64 
65  for (i = 0; i < ARRAY_SIZE(container->async_handles); i++) {
67 
68  if (handle->data != NULL)
70 
71  uv_close((uv_handle_t*) handle, NULL);
72  }
73 
74  uv_close((uv_handle_t*) handle, NULL);
75 }
76 
77 
78 BENCHMARK_IMPL(million_async) {
81  uv_loop_t* loop;
82  int timeout;
83  unsigned i;
84 
86  timeout = 5000;
87 
88  container = malloc(sizeof(*container));
89  ASSERT(container != NULL);
92 
93  for (i = 0; i < ARRAY_SIZE(container->async_handles); i++) {
96  handle->data = NULL;
97  }
98 
103  printf("%s async events in %.1f seconds (%s/s, %s unique handles seen)\n",
105  timeout / 1000.,
106  fmt(container->async_events / (timeout / 1000.)),
108  free(container);
109 
111  return 0;
112 }
async_greeter_server_with_graceful_shutdown.loop
loop
Definition: async_greeter_server_with_graceful_shutdown.py:59
async_container::async_events
unsigned async_events
Definition: benchmark-million-async.c:26
ARRAY_SIZE
#define ARRAY_SIZE(array)
Definition: bloaty.cc:101
task.h
fastrand
static unsigned fastrand(void)
Definition: benchmark-million-async.c:36
async_container::handles_seen
unsigned handles_seen
Definition: benchmark-million-async.c:27
BENCHMARK_IMPL
BENCHMARK_IMPL(million_async)
Definition: benchmark-million-async.c:78
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
ASSERT
#define ASSERT(expr)
Definition: task.h:102
done
static volatile int done
Definition: benchmark-million-async.c:31
uv_thread_join
UV_EXTERN int uv_thread_join(uv_thread_t *tid)
Definition: libuv/src/unix/thread.c:271
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
async_cb
static void async_cb(uv_async_t *handle)
Definition: benchmark-million-async.c:53
uv_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: unix/core.c:112
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
uv_async_s
Definition: uv.h:834
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
arg
Definition: cmdline.cc:40
timer_cb
static void timer_cb(uv_timer_t *handle)
Definition: benchmark-million-async.c:59
uv_thread_create
UV_EXTERN int uv_thread_create(uv_thread_t *tid, uv_thread_cb entry, void *arg)
Definition: libuv/src/unix/thread.c:209
g
struct @717 g
uv_timer_s
Definition: uv.h:850
uv.h
MAKE_VALGRIND_HAPPY
#define MAKE_VALGRIND_HAPPY()
Definition: task.h:229
testing::internal::fmt
GTEST_API_ const char * fmt
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1808
uv_async_init
UV_EXTERN int uv_async_init(uv_loop_t *, uv_async_t *async, uv_async_cb async_cb)
Definition: unix/async.c:44
thread_id
static uv_thread_t thread_id
Definition: benchmark-million-async.c:32
thread_cb
static void thread_cb(void *arg)
Definition: benchmark-million-async.c:43
handle
static csh handle
Definition: test_arm_regression.c:16
async_container::async_handles
uv_async_t async_handles[1024 *1024]
Definition: benchmark-million-async.c:28
uv_handle_s
Definition: uv.h:441
uv_timer_start
UV_EXTERN int uv_timer_start(uv_timer_t *handle, uv_timer_cb cb, uint64_t timeout, uint64_t repeat)
Definition: timer.c:66
uv_thread_t
pthread_t uv_thread_t
Definition: unix.h:134
uv_loop_s
Definition: uv.h:1767
uv_timer_init
UV_EXTERN int uv_timer_init(uv_loop_t *, uv_timer_t *handle)
Definition: timer.c:58
timer_handle
static uv_timer_t timer_handle
Definition: benchmark-loop-count.c:32
async_container
Definition: benchmark-million-async.c:25
timeout
uv_timer_t timeout
Definition: libuv/docs/code/uvwget/main.c:9
container
static struct async_container * container
Definition: benchmark-million-async.c:33
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
uv_async_send
UV_EXTERN int uv_async_send(uv_async_t *async)
Definition: unix/async.c:62


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:36