Skip to content

Instantly share code, notes, and snippets.

@polotek
Created August 9, 2010 05:04
Show Gist options
  • Save polotek/514968 to your computer and use it in GitHub Desktop.
Save polotek/514968 to your computer and use it in GitHub Desktop.
commit 34488642c115366db65c2680ccc3c4d4138132b0
Date: Fri Jul 23 19:51:04 2010 -0400
first around at surfacing thread usage data. broken :(
diff --git a/deps/libeio/eio.c b/deps/libeio/eio.c
index 6f61f5d..1c23b0d 100644
--- a/deps/libeio/eio.c
+++ b/deps/libeio/eio.c
@@ -212,7 +212,7 @@ static int tvdiff (struct timeval *tv1, struct timeval *tv2)
+ ((tv2->tv_usec - tv1->tv_usec) >> 10);
}
-static unsigned int started, idle, wanted = 4;
+static unsigned int started, idle, wanted = 6;
static void (*want_poll_cb) (void);
static void (*done_poll_cb) (void);
@@ -314,6 +314,11 @@ static unsigned int etp_nthreads (void)
return retval;
}
+static unsigned int etp_nmax (void)
+{
+ return wanted;
+}
+
/*
* a somewhat faster data structure might be nice, but
* with 8 priorities this actually needs <20 insns
@@ -744,6 +749,11 @@ unsigned int eio_nthreads (void)
return etp_nthreads ();
}
+unsigned int eio_nmax (void)
+{
+ return etp_nmax();
+}
+
void eio_set_max_poll_time (double nseconds)
{
etp_set_max_poll_time (nseconds);
diff --git a/deps/libeio/eio.h b/deps/libeio/eio.h
index 1a5dc3d..130b6a6 100644
--- a/deps/libeio/eio.h
+++ b/deps/libeio/eio.h
@@ -223,9 +223,10 @@ void eio_set_max_parallel (unsigned int nthreads);
void eio_set_max_idle (unsigned int nthreads);
unsigned int eio_nreqs (void); /* number of requests in-flight */
-unsigned int eio_nready (void); /* number of not-yet handled requests */
-unsigned int eio_npending (void); /* numbe rof finished but unhandled requests */
+unsigned int eio_nready (void); /* number of not-yet started requests */
+unsigned int eio_npending (void); /* number of finished but unhandled requests */
unsigned int eio_nthreads (void); /* number of worker threads in use currently */
+unsigned int eio_nmax (void); /* max number of threads wanted */
/*****************************************************************************/
/* convinience wrappers */
diff --git a/lib/fs.js b/lib/fs.js
index 5fb1950..653649b 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -608,6 +608,8 @@ var ReadStream = fs.ReadStream = function(path, options) {
options = options || {};
+ if(options.encoding) this.setEncoding(options.encoding);
+
// Mixin options into this
var keys = Object.keys(options);
for (var index = 0, length = keys.length; index < length; index++) {
@@ -890,7 +892,7 @@ WriteStream.prototype.write = function (data) {
if (Buffer.isBuffer(data)) {
this._queue.push([fs.write, data, 0, data.length, null, cb]);
} else {
- var encoding = 'utf8';
+ var encoding = this.encoding || 'utf8';
if (typeof(arguments[1]) == 'string') encoding = arguments[1];
this._queue.push([fs.write, data, undefined, encoding, cb]);
}
diff --git a/src/node.cc b/src/node.cc
index 6915c18..b13f7ce 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -59,6 +59,12 @@ static Persistent<String> errno_symbol;
static Persistent<String> syscall_symbol;
static Persistent<String> errpath_symbol;
+static Persistent<String> io_reqs_symbol;
+static Persistent<String> io_active_symbol;
+static Persistent<String> io_pending_symbol;
+static Persistent<String> io_idle_symbol;
+static Persistent<String> io_max_symbol;
+
static Persistent<String> rss_symbol;
static Persistent<String> vsize_symbol;
static Persistent<String> heap_total_symbol;
@@ -1182,6 +1188,35 @@ static void CheckStatus(EV_P_ ev_timer *watcher, int revents) {
}
+ v8::Handle<v8::Value> IOThreadUsage(const v8::Arguments& args) {
+ HandleScope scope;
+ assert(args.Length() == 0);
+
+ unsigned int io_reqs = eio_nreqs(),
+ io_active = eio_nthreads(),
+ io_pending = eio_npending(),
+ io_max = eio_nmax(),
+ io_idle = io_max - (io_active + io_pending);
+
+ Local<Object> info = Object::New();
+
+ if (io_active_symbol.IsEmpty()) {
+ io_reqs_symbol = NODE_PSYMBOL("requests");
+ io_active_symbol = NODE_PSYMBOL("active");
+ io_pending_symbol = NODE_PSYMBOL("pending");
+ io_idle_symbol = NODE_PSYMBOL("idle");
+ io_max_symbol = NODE_PSYMBOL("max");
+ }
+
+ info->Set(io_reqs_symbol, Integer::NewFromUnsigned(io_reqs));
+ info->Set(io_active_symbol, Integer::NewFromUnsigned(io_active));
+ info->Set(io_pending_symbol, Integer::NewFromUnsigned(io_pending));
+ info->Set(io_idle_symbol, Integer::NewFromUnsigned(io_idle));
+ info->Set(io_max_symbol, Integer::NewFromUnsigned(io_max));
+
+ return scope.Close(info);
+ }
+
v8::Handle<v8::Value> MemoryUsage(const v8::Arguments& args) {
HandleScope scope;
assert(args.Length() == 0);
@@ -1623,6 +1658,7 @@ static void Load(int argc, char *argv[]) {
NODE_SET_METHOD(process, "umask", Umask);
NODE_SET_METHOD(process, "dlopen", DLOpen);
NODE_SET_METHOD(process, "kill", Kill);
+ NODE_SET_METHOD(process, "ioThreadUsage", IOThreadUsage);
NODE_SET_METHOD(process, "memoryUsage", MemoryUsage);
NODE_SET_METHOD(process, "checkBreak", CheckBreak);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment