nonblocking

Java thread per connection model vs NIO

眉间皱痕 提交于 2019-11-28 15:53:57
Is the non-blocking Java NIO still slower than your standard thread per connection asynchronous socket? In addition, if you were to use threads per connection, would you just create new threads or would you use a very large thread pool? I'm writing an MMORPG server in Java that should be able to scale 10000 clients easily given powerful enough hardware, although the maximum amount of clients is 24000 (which I believe is impossible to reach for the thread per connection model because of a 15000 thread limit in Java). From a three year old article, I've heard that blocking IO with a thread per

Using select() for non-blocking sockets to connect always returns 1

…衆ロ難τιáo~ 提交于 2019-11-28 10:23:48
This question is very similar (or almost identical) to In a non blocking socket connect, select() always returns 1 ; however, I can't seem to find where my code is faltering. I am using non-blocking sockets and want to use select() when connecting a client to a server to check for timeout/success. The problem is select() is always returning 1 almost immediately, even when I don't even have the server running and there is nothing to connect to. Thanks in advance for the help, code snippet is as follows: //Loop through the addrinfo structs and try to connect to the first one we can for(p =

NodeJs how to create a non-blocking computation

只愿长相守 提交于 2019-11-28 09:48:57
I am trying to get my head around creating a non-blocking piece of heavy computation in nodejs. Take this example (stripped out of other stuff): http.createServer(function(req, res) { console.log(req.url); sleep(10000); res.end('Hello World'); }).listen(8080, function() { console.log("ready"); }); As you can imagine, if I open 2 browser windows at the same time, the first will wait 10 seconds and the other will wait 20, as expected. So, armed with the knowledge that a callback is somehow asynchronous I removed the sleep and put this instead: doHeavyStuff(function() { res.end('Hello World'); })

non blocking socket select returns 1 after connect

江枫思渺然 提交于 2019-11-28 09:43:17
问题 First of all I would like to say that this is another problem than this one: Similar but not the same My code looks like this: struct addrinfo hints, *res; struct sockaddr* serveraddr; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; int res2 = getaddrinfo(ip, port, &hints, &res); printf("getaddrinfo() res: %d, %d\n", res2, errno); serveraddr = res->ai_addr; //create new socket int soc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); printf("socket()

TNonblockingServer, TThreadedServer and TThreadPoolServer, which one fits best for my case?

拜拜、爱过 提交于 2019-11-28 09:11:55
Our analytic server is written in c++. It basically queries underlying storage engine and returns a fairly big structured data via thrift. A typical requests will take about 0.05 to 0.6 seconds to finish depends on the request size. I noticed that there are a few options in terms of which Thrift server we can use in the c++ code, specifically TNonblockingServer, TThreadedServer, and TThreadPoolServer. It seems like TNonblockingServer is the way to go since it can support much more concurrent requests and still using a thread pool behind the scene to crunch through the tasks. It also avoids the

sending a non-blocking HTTP POST request

余生长醉 提交于 2019-11-28 08:28:34
I have a two websites in php and python. When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server. Is it possible to continue running a php/python script after sending a response to the user. In that case I'll first reply to the user and only then send the HTTP POST request to the remote server. Is it possible to create a non-blocking HTTP client in php/python without handling the response at all? A solution that will have the same logic in php and

Detect key press (non-blocking) w/o getc/gets in Ruby

江枫思渺然 提交于 2019-11-28 07:33:00
I have a simple task that needs to wait for something to change on the filesystem (it's essentially a compiler for prototypes). So I've a simple infinite loop with a 5 second sleep after the check for changed files. loop do # if files changed # process files # and puts result sleep 5 end Instead of the Ctrl+C salute, I'd rather be able to test and see if a key has been pressed, without blocking the loop. Essentially I just need a way to tell if there are incoming key presses, then a way to grab them until a Q is met, then exit out of the program. What I want is: def wait_for_Q key_is_pressed &

How to make non-blocking javascript code?

混江龙づ霸主 提交于 2019-11-28 07:21:43
How can I make a simple, non-block Javascript function call? For example: //begin the program console.log('begin'); nonBlockingIncrement(10000000); console.log('do more stuff'); //define the slow function; this would normally be a server call function nonBlockingIncrement(n){ var i=0; while(i<n){ i++; } console.log('0 incremented to '+i); } outputs "beginPage" "0 incremented to 10000000" "do more stuff" How can I form this simple loop to execute asynchronously and output the results via a callback function? The idea is to not block "do more stuff": "beginPage" "do more stuff" "0 incremented to

Sockets in C#, how can I asynchronously read and write data through a NetworkStream

旧街凉风 提交于 2019-11-28 06:26:03
问题 [I am limited to Visual Studio 2010, and therefore, C# 4. async and await are not available to me.] I'm working on network architecture for a project of mine, that sends packets of data over a network between a server and a client, but the client and server must continue running while waiting, so the code has to be non-blocking, so I thought to use the asynchronous methods. However, except for simple synchronous one-time IO, I don't know much about what to do, especially when using a

Single Threaded Event Loop vs Multi Threaded Non Blocking Worker in Node.JS

梦想的初衷 提交于 2019-11-28 06:03:51
Node.JS biggest advantage is it's non blocking nature. It's single threaded, so it doesn't need to spawn a new thread for each new incoming connection. Behind the event-loop (which is in fact single threaded), there is a "Non blocking Worker". This thing is not single threaded anymore, so (as far as I understood) it can spawn a new thread for each task. Maybe I misunderstood something, but where exactly is the advantage. If there are to many tasks to handle, wouldn't be the Non Blocking Working turn into a Blocking Worker? Thanks Christian You need to read about libuv , the "magic" behind node