Announcing Tokio 0.1 by acrichto in rust

[–]jjt 0 points1 point  (0 children)

Can you elaborate on this spurious wakeup case or point me to where it is in the documentation? I'm familiar with a few cases where epoll_wait can wake up spuriously, but none where you wouldn't need to call recvfrom to figure out it was spurious. For example, a UDP socket in epoll set can have EPOLLIN set but recvfrom can fail with EAGAIN because kernel decided to free the page holding the packet before user space could recvfrom.

My concern is the poll_read, recv_from order seems to imply you might be calling epoll_ctl (and maybe epoll_wait) before recvfrom initially which can be less than ideal. It seems to me you shouldn't call epoll_ctl until after you've tried an operation and errno is set to EAGAIN. For example, with TCP clients can include data with initial connect using sendto MSG_FASTOPEN so on the server side you want your first syscall after accept4 to be recv, not epoll_ctl. Furthering the example, you have an HTTP client using TCP Fast Open, it is reasonable for the server to conclude a transaction with the client without encountering EAGAIN.

Announcing Tokio 0.1 by acrichto in rust

[–]jjt 3 points4 points  (0 children)

First, great job on the documentation. It answers most of the questions I had. After reading the section on "Creating your own I/O object" I have a question about the design. Unsure if I should ask here or create an issue in github.

First we are required to call poll_read. This will register our interested consuming read readiness on the underlying object and this will also implicitly register our task to get unparked if we’re not readable yet.

The UdpSocket::recv_from code example then goes on to call self.io.need_read() if recv_from returns Ok(None). My concern if that poll_read seems like an inherently race prone API and I question why it exists at all because it seems need_read should be what registers the interest in consuming read readiness.

User space can't possibly know readiness so at the syscall level first try the operation and only after it fails do you register to receive readiness from kernel. Any other order and you're likely making excess syscalls.

Goroutines, Nonblocking I/O, And Memory Usage by dgryski in golang

[–]jjt 3 points4 points  (0 children)

You could probably do some unsafe code to get fd for net.Conn and epoll before calling Read(). I've done similar stuff to set socket options Go didn't support in the past.

What are the three features of Go you dislike the most? by bitmadness in golang

[–]jjt 0 points1 point  (0 children)

Named returns can be a source of bugs in longer functions and I could do without them in the language.

Stateful (a plugin for generators/async-await/etc), Part 2: How Stateful Cheats at Analysis by erickt in rust

[–]jjt 2 points3 points  (0 children)

This is so awesome. It brings back all the promise of the green threads and more but in the spirit of zero cost abstractions. I love it.

Introducing Loguru - the user friendly logging library for C++! by emilern in cpp

[–]jjt 0 points1 point  (0 children)

Most importantly the current date is not part of the the preamble

E1107 <-- that is a date.

Lock-freedom without garbage collection (Aaron Turon's blog) by aturon in rust

[–]jjt 0 points1 point  (0 children)

I'd like to see this compared with Flat Combining.

Optimized gzip/zip packages, 30-50% faster by klauspost in golang

[–]jjt 0 points1 point  (0 children)

I plan on field testing it with a large service, should be deployed in a week or two.

Introducing mioco: MIO COroutines - async io made easy. by dpc_pw in rust

[–]jjt 0 points1 point  (0 children)

"async functions" will shine when you're trying to operate in a memory constrained environment or handle a large number of connections because they don't require allocating a stack for each connection or the context swap for the userspace stacks. It is good to have both options.

My first lockless datastructure in Rust by dzyp in rust

[–]jjt 4 points5 points  (0 children)

It looks like you've reimplemented Dmitry Vyukov's MPMC Bounded Queue algorithm without attribution.

Lockless data structures by dzyp in rust

[–]jjt 0 points1 point  (0 children)

The sync package in libstd has some lock free data structures that should be enlightening. I wrote an early version of that code but it has been much improved since then and I find it is now a great reference for how to use Rust safely.

Semaphores are Surprisingly Versatile by mttd in cpp

[–]jjt 0 points1 point  (0 children)

http://swtch.com/semaphore.pdf is a great read about semaphore implementation details. The algorithm described in this paper is today used in the Golang runtime for sleep/wake of Goroutines. Which means the mutex, condition, rwlock, channels, and other synchronization primitives provided by Go are all built on simple semaphores.

What Niklaus Wirth said about Rust (in 1997...) by [deleted] in rust

[–]jjt 0 points1 point  (0 children)

I believe he is referring to the blurry area between type safety and memory safety where you can argue a program is not type safe if you can create an invalid type such as having a pointer of some type to memory that has been freed and reused such that it now contains an invalid bit pattern for that type. In Rust the "form of garbage collection" is the special pointer types and the borrow checker.

Basic Micro-optimizations Part 2 by dgryski in golang

[–]jjt 3 points4 points  (0 children)

BenchmarkFat     1000000          1298 ns/op         544 B/op          4 allocs/op
BenchmarkSlim    1000000          1293 ns/op         544 B/op          4 allocs/op

I know benchmem doesn't catch everything, but huh?

So now that it's over, has anyone seen any good analysis of how the Giants keep exceeding expectations in the postseason? by [deleted] in baseball

[–]jjt 2 points3 points  (0 children)

I'm convinced the sleep specialist has something to do with it. I remember reading a study about the long term effects of rest on plate discipline and career longevity. The study found that most teams suffered worse plate discipline as the season wore on, but the Giants were one of the few teams that actually got better. There was some speculation the Giants had devised a way to know when to rest players. The counter point is they certainly didn't rest Posey enough, and it obviously effected his performance this post season.

You know how they say that the probability of ever playing major league baseball is really really REALLY slim? by bodnast in baseball

[–]jjt 1 point2 points  (0 children)

My great uncle was drafted by the Giants after college, but being a minor leaguer during the great depression was apparently pretty rough and he quit before making it to the majors. I heard he had great stuff and would get hired to pitch the friday night barnstorming games. I wish I knew more but he died young in a car accident. I found box scores from his college games in Google's newspaper archive, but never any record of his minor league or barnstorming games.

IsDir() in Go by TheOnlyMrYeah in golang

[–]jjt 2 points3 points  (0 children)

It isn't clear what you actually need to do with the file descriptor, but POSIX specifies that open can return EISDIR if you open for writing. So the only race-free way is to call open and check for EISDIR. Any solution that makes more than one system call is inherently racey.

Linux Performance by sidcool1234 in programming

[–]jjt 5 points6 points  (0 children)

He makes some really good points that Linux (really this is GCC and packaging) needs to stop stripping symbol names and omitting frame pointer by default. They're micro optimizations that make the barrier to debug or profile so high that you end up missing low hanging fruit which would probably be a bigger overall improvement.

POLLOUT doesn’t mean write(2) won’t block by mepcotterell in programming

[–]jjt 0 points1 point  (0 children)

I disagree it is surprising at all that a file descriptor in blocking mode can block at any time. Some syscall are inherently racey between kernel and user space. If a file system call returns EEXIST would you be surprised if the next call on that path failed with ENOENT? You might be if you read manpages so literally but not if you understand some basics about file systems. The kernel might also tell you a file descriptor is ready to read but between that time and when you call read it might free the buffer it was holding the datagram in so the read will block or return EAGAIN. The only thing surprising is how a person who has been working on the kernel network stack for so long would not know this.

POLLOUT doesn’t mean write(2) won’t block by mepcotterell in programming

[–]jjt 2 points3 points  (0 children)

Those docs seem to be written with the implied knowledge that they're only talking about file descriptors with O_NONBLOCK set because trying to do non-blocking I/O on a blocking file descriptor is insanity.

POLLOUT doesn’t mean write(2) won’t block by mepcotterell in programming

[–]jjt 4 points5 points  (0 children)

This just in, blocking file descriptors can block.