Skip to content

Instantly share code, notes, and snippets.

@sustrik
Created March 18, 2011 10:33
Show Gist options
  • Save sustrik/875871 to your computer and use it in GitHub Desktop.
Save sustrik/875871 to your computer and use it in GitHub Desktop.
diff --git a/src/config.hpp b/src/config.hpp
index f144512..85a6b0a 100644
--- a/src/config.hpp
+++ b/src/config.hpp
@@ -29,7 +29,7 @@ namespace zmq
enum
{
// Maximum number of sockets that can be opened at the same time.
- max_sockets = 512,
+ max_sockets = 40000,
// Number of new messages in message pipe needed to trigger new memory
// allocation. Setting this parameter to 256 decreases the impact of
diff --git a/src/yqueue.hpp b/src/yqueue.hpp
index e436ea4..7dc9817 100644
--- a/src/yqueue.hpp
+++ b/src/yqueue.hpp
@@ -26,10 +26,13 @@
#include "err.hpp"
#include "atomic_ptr.hpp"
+#include "atomic_counter.hpp"
namespace zmq
{
+//extern atomic_counter_t gcounter;
+
// yqueue is an efficient queue implementation. The main goal is
// to minimise number of allocations/deallocations needed. Thus yqueue
// allocates/deallocates elements in batches of N.
@@ -51,6 +54,8 @@ namespace zmq
inline yqueue_t ()
{
begin_chunk = (chunk_t*) malloc (sizeof (chunk_t));
+//gcounter.add (1);
+//printf ("%d\n", (int) gcounter.get ());
alloc_assert (begin_chunk);
begin_pos = 0;
back_chunk = NULL;
@@ -65,16 +70,23 @@ namespace zmq
while (true) {
if (begin_chunk == end_chunk) {
free (begin_chunk);
+//gcounter.sub (1);
+//printf ("%d\n", (int) gcounter.get ());
break;
}
chunk_t *o = begin_chunk;
begin_chunk = begin_chunk->next;
free (o);
+//gcounter.sub (1);
+//printf ("%d\n", (int) gcounter.get ());
}
chunk_t *sc = spare_chunk.xchg (NULL);
- if (sc)
+ if (sc) {
free (sc);
+//gcounter.sub (1);
+//printf ("%d\n", (int) gcounter.get ());
+ }
}
// Returns reference to the front element of the queue.
@@ -106,6 +118,8 @@ namespace zmq
sc->prev = end_chunk;
} else {
end_chunk->next = (chunk_t*) malloc (sizeof (chunk_t));
+//gcounter.add (1);
+//printf ("%d\n", (int) gcounter.get ());
alloc_assert (end_chunk->next);
end_chunk->next->prev = end_chunk;
}
@@ -140,6 +154,8 @@ namespace zmq
end_pos = N - 1;
end_chunk = end_chunk->prev;
free (end_chunk->next);
+//gcounter.sub (1);
+//printf ("%d\n", (int) gcounter.get ());
end_chunk->next = NULL;
}
}
@@ -157,8 +173,11 @@ namespace zmq
// so for cache reasons we'll get rid of the spare and
// use 'o' as the spare.
chunk_t *cs = spare_chunk.xchg (o);
- if (cs)
+ if (cs) {
free (cs);
+//gcounter.sub (1);
+//printf ("%d\n", (int) gcounter.get ());
+ }
}
}
diff --git a/src/zmq.cpp b/src/zmq.cpp
index 929e51c..32ef4a3 100644
--- a/src/zmq.cpp
+++ b/src/zmq.cpp
@@ -66,6 +66,13 @@
#endif
+
+#include "atomic_counter.hpp"
+namespace zmq
+{
+ atomic_counter_t gcounter;
+}
+
void zmq_version (int *major_, int *minor_, int *patch_)
{
*major_ = ZMQ_VERSION_MAJOR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment