nonblocking

How do Jetty and other containers leverage NIO while sticking to the Servlet specification?

人盡茶涼 提交于 2019-12-03 02:01:55
问题 I'm new to NIO, and I am trying to figure out how Jetty leverages NIO. My understanding of how traditional servlet containers that use Blocking IO service a request is as follows: A request arrives A thread is allocated to process the request and the servlet method ( doGet etc) is invoked Servlet method is handed an InputStream and OutputStream The servlet method reads from the InputStream and writes to the OutputStream The InputStream and OutputStream are basically tied to the respective

Can I make a fully non-blocking backend application with http-kit and core.async?

你离开我真会死。 提交于 2019-12-03 01:39:47
问题 I'm wondering if it's possible to put together a fully non-blocking Clojure backend web application with http-kit. (Actually any Ring-compatible http server would be fine by me; I'm mentioning http-kit because it claims to have an event-driven, non-blocking model). EDIT: TL;DR This question is a symptom of some misconceptions I had about the nature of non-blocking/asynchronous/event-driven systems. In case you're in the same place as I was, here are some clarifications. Making an event-driven

Play Framework 2.X and blocking database call

给你一囗甜甜゛ 提交于 2019-12-03 01:35:33
I'm a little confused. From the documentation : Play default thread pool - This is the default thread pool in which all application code in Play Framework is executed, excluding some iteratees code. It is an Akka dispatcher, and can be configured by configuring Akka, described below. By default, it has one thread per processor. Does it bring benefit to wrap a blocking database call in a Future , the call to the Future being itself wrapped by an async controller (returning it), in order to let the default thread pool handling other users requests? It would just move the blocking code inside

Non-blocking (async) DNS resolving in Java

一笑奈何 提交于 2019-12-03 01:11:50
Is there a clean way to resolve a DNS query (get IP by hostname) in Java asynchronously, in non-blocking way (i.e. state machine, not 1 query = 1 thread - I'd like to run tens of thousands queries simultaneously, but not run tens of thousands of threads)? What I've found so far: Standard InetAddress.getByName() implementation is blocking and looks like standard Java libraries lack any non-blocking implementations. Resolving DNS in bulk question discusses similar problem, but the only solution found is multi-threaded approach (i.e. one thread working on only 1 query in every given moment of a

Python/Erlang: What's the difference between Twisted, Stackless, Greenlet, Eventlet, Coroutines? Are they similar to Erlang processes?

余生长醉 提交于 2019-12-03 00:33:39
问题 My incomplete understanding is that Twisted, Stackless, Greenlet, Eventlet, Coroutines all make use of async network IO and userland threads that are very lightweight and quick to switch. But I'm not sure what are the differences between them. Also they sound very similar to Erlang processes. Are they pretty much the same thing? Anyone who could help me understand this topic more would be greatly appreciated. 回答1: First of all, non-blocking I/O has nothing in common with green threads or

How to read named FIFO non-blockingly?

谁说胖子不能爱 提交于 2019-12-02 22:36:56
I create a FIFO, and periodically open it in read-only and non-blockingly mode from a.py: os.mkfifo(cs_cmd_fifo_file, 0777) io = os.open(fifo, os.O_RDONLY | os.O_NONBLOCK) buffer = os.read(io, BUFFER_SIZE) From b.py, open the fifo for writing: out = open(fifo, 'w') out.write('sth') Then a.py will raise an error: buffer = os.read(io, BUFFER_SIZE) OSError: [Errno 11] Resource temporarily unavailable Anyone know what's wrong? According to the manpage of read(2) : EAGAIN or EWOULDBLOCK The file descriptor fd refers to a socket and has been marked nonblocking (O_NONBLOCK), and the read would block.

Is O_NONBLOCK being set a property of the file descriptor or underlying file?

喜夏-厌秋 提交于 2019-12-02 19:12:13
From what I have been reading on The Open Group website on fcntl , open , read , and write , I get the impression that whether O_NONBLOCK is set on a file descriptor, and hence whether non-blocking I/O is used with the descriptor, should be a property of that file descriptor rather than the underlying file. Being a property of the file descriptor means, for example, that if I duplicate a file descriptor or open another descriptor to the same file, then I can use blocking I/O with one and non-blocking I/O with the other. Experimenting with a FIFO, however, it appears that it is not possible to

How is Non-Blocking IO implemented?

有些话、适合烂在心里 提交于 2019-12-02 18:11:22
In Java or C# or some other languages, there are non-blocking IO facilities, e.g., for sockets. So I can give my callback functions to the non-blocking IO and once the non-blocking IO receives anything, it will call my callbacks. I am wondering how they are implemented. If I create non-blocking IO, behind the scene, does Java or C# just create background threads for them? or the OS underlying has native support for them? On Windows there is underlying OS support for non-blocking I/O, and Microsoft's CLR takes advantage of that. Other CLR implementations (mono) probably do as well, but I don't

How do Jetty and other containers leverage NIO while sticking to the Servlet specification?

懵懂的女人 提交于 2019-12-02 15:38:42
I'm new to NIO, and I am trying to figure out how Jetty leverages NIO. My understanding of how traditional servlet containers that use Blocking IO service a request is as follows: A request arrives A thread is allocated to process the request and the servlet method ( doGet etc) is invoked Servlet method is handed an InputStream and OutputStream The servlet method reads from the InputStream and writes to the OutputStream The InputStream and OutputStream are basically tied to the respective streams of the underlying Socket What is different when an NIO connector is used? My guess is along the

simultaneously read and write on the same socket in C or C++

元气小坏坏 提交于 2019-12-02 15:32:01
I am implementing a simple server, that accepts a single connection and then uses that socket to simultaneously read and write messages from the read and write threads. What is the safe and easy way to simultaneously read and write from the same socket descriptor in c/c++ on linux? I dont need to worry about multiple threads read and writing from the same socket as there will be a single dedicated read and single dedicated write thread writing to the socket. In the above scenario, is any kind of locking required? Does the above scenario require non blocking socket? Is there any opensource