News for hackers. Stuff that matters.
Re:Show HN: ZFS Implementation in Python by lunixbochs on Saturday May 04, 2019 @12:18PM (#19827359)
Note: this was implemented without referencing any ZFS source code and should not be subject to the CDDL.
Re:Show HN: ZFS Implementation in Python by josteink on Saturday May 04, 2019 @01:00PM (#19827681)
So we port this python to something not slow, and all the kernel-people can shut up about ZFS being terrible ;)
Re:Show HN: ZFS Implementation in Python by aidenn0 on Saturday May 04, 2019 @03:34PM (#19828726)
I can Port from Python -> Common Lisp at a rate of ~100 LoC per hour, and that's a pretty friendly port (the yield expression is the only thing that can't be just done line-by-line; truthyness is the only real "gotcha" as there are a lot of "false" values in Python, but only 1.5 in Lisp[1]).

1: I say 1.5 because there is only one false value, but it has 2 idiomatic meanings: nil (equivalent to python's None) and the empty list.

Re:Show HN: ZFS Implementation in Python by j88439h84 on Saturday May 04, 2019 @01:05PM (#19827724)
Dont forget, pypy is fast.
Re:Show HN: ZFS Implementation in Python by cure on Saturday May 04, 2019 @01:55PM (#19828036)
PyPy is faster than Python, yes. But Go, C and many other (compiled) languages are way faster than PyPy. Plus, if you use a language like Go or Rust then you avoid Python's GIL and you'll have much more reasonable memory usage. Best of all, deploying is a matter of copying a binary, rather than having to deal with the absolute disaster that is Python packaging.
Re:Show HN: ZFS Implementation in Python by deaddodo on Sunday May 05, 2019 @05:16AM (#19831897)
> Plus, if you use a language like Go or Rust then you avoid Python's GIL

No, but then you run into Go's GC and green threads. File systems fit squarely in the realms of "systems programming" (old definition [1], not new). Languages like Ada, Pascal, C/C++, Rust and D (without GC).

[1] - https://en.wikipedia.org/wiki/System_programming_language

Re:Show HN: ZFS Implementation in Python by klyrs on Saturday May 04, 2019 @06:01PM (#19829663)
Filesystem with a GIL, what could possibly go wrong? /s
Re:Show HN: ZFS Implementation in Python by emmelaich on Saturday May 04, 2019 @11:37PM (#19830981)
A lot less will go wrong than a filesystem without a GIL.

GIL is for safety and correctness, not speed.

Re:Show HN: ZFS Implementation in Python by y4mi on Sunday May 05, 2019 @03:48AM (#19831691)
Uh, no?

Python's global interpreter lock was added for single threaded speed and c library integrations, which often can't be used multithreaded

There was some talk about removing it recentlish to improve pythons multithreaded performance and Guido said something along the lines of

> "I'll remove it as long as single threaded performance doesn't suffer"

Which nobody succeeded in

Re:Show HN: ZFS Implementation in Python by nine_k on Saturday May 04, 2019 @06:52PM (#19829895)
Go? A GC'd language in kernel? (Well, yes, this has been done, from Lua to Haskell, but only experimentally.)
Re:Show HN: ZFS Implementation in Python by hu3 on Saturday May 04, 2019 @07:34PM (#19830072)
I wouldn't advise writing low level stuff in Go but people do enjoy a challenge from time to time: https://news.ycombinator.com/item?id=18399389
Re:Show HN: ZFS Implementation in Python by pjmlp on Sunday May 05, 2019 @05:08AM (#19831872)
I wouldn't consider the workstations sold by Xerox, TI, Connecting Machines, the OS research department at ETHZ or the Microsoft’s natural language search service for the West Coast and Asia, just experiments.
Re:Show HN: ZFS Implementation in Python by weberc2 on Saturday May 04, 2019 @09:03PM (#19830436)
Python is also a GC’d language...
Re:Show HN: ZFS Implementation in Python by twa927 on Sunday May 05, 2019 @05:23AM (#19831917)
CPython is mostly reference-counted.
Re:Show HN: ZFS Implementation in Python by int_19h on Sunday May 05, 2019 @09:00PM (#19836093)
With a synchronous garbage collector for cycles. Which is like the worst of both worlds, since you get the constant overhead of refcounting, plus unpredictable interruptions of unspecified duration that can happen every time a new object that might contain references to other objects is created.

To be fair, the GC can be disabled. But it's only safe to do so when you know there are no cycles, and even when such guarantee can be had for your own code, I've never seen a library guarantee that to API clients.

Re:Show HN: ZFS Implementation in Python by BlackFingolfin on Sunday May 05, 2019 @07:43AM (#19832321)
And reference counting is a form of GC
Re:Show HN: ZFS Implementation in Python by fnord123 on Sunday May 05, 2019 @06:29AM (#19832100)
>PyPy is faster than Python, yes.

Python is only slow if you use it wrong:

https://apenwarr.ca/diary/2011-10-pycodeconf-apenwarr.pdf

Re:Show HN: ZFS Implementation in Python by GuB-42 on Saturday May 04, 2019 @06:50PM (#19829887)
Maybe plenty fast for most applications but a filesystem is not one of these IMHO, especially for something as naturally resource hungry as ZFS.

A good filesystem implementation requires tight memory management and good control of what happens at the OS level. I am not saying it can't be be done in python, but it clearly isn't the right tool for the job.

I meant that for a production implementation. Python is perfectly fine for a proof of concept, in fact, it may be better than jumping straight down to C. But keeping it for production is foolish IMHO.

Re:Show HN: ZFS Implementation in Python by spullara on Saturday May 04, 2019 @01:45PM (#19827976)
Faster that CPython doesn't mean it is fast.
Re:Show HN: ZFS Implementation in Python by twa927 on Saturday May 04, 2019 @04:45PM (#19829269)
I was trying to speed up a log processing service running on PyPy by rewriting it in Java. I was surprised that the result was about twice slower (I know Java quite well and I didn't see obvious optimizations; most of the time was spent in GC). So it can be quite fast even in more absolute terms (VM languages), at least for some types of code.
Re:Show HN: ZFS Implementation in Python by spullara on Saturday May 04, 2019 @05:22PM (#19829475)
If more than 1% of your time is in GC you are doing something very wrong.
Re:Show HN: ZFS Implementation in Python by michaelmrose on Saturday May 04, 2019 @06:20PM (#19829746)
The fact that a singular implementation was better than java says less about the languages and more about the particular software.
Re:Show HN: ZFS Implementation in Python by tigershark on Saturday May 04, 2019 @05:41PM (#19829557)
I know that it’s asking a lot, but any chance that you can post a minimum reproducible sample? From what I know it is quite smelly...
Re:Show HN: ZFS Implementation in Python by twa927 on Saturday May 04, 2019 @05:49PM (#19829604)
I don't have access to this codebase now but I'll try to write some benchmark.
Re:Show HN: ZFS Implementation in Python by tigershark on Saturday May 04, 2019 @05:55PM (#19829634)
If you manage to do it would be awesome, otherwise thanks a lot anyway for the effort :) I’m just curious to understand why it happens because it’s exactly the opposite of what I would expect. The only explanation that comes to my mind is excessive gc as someone else already mentioned, but it would be interesting to see the original code.
Re:Show HN: ZFS Implementation in Python by twa927 on Saturday May 04, 2019 @06:24PM (#19829765)
I started doing it but yes, it's too much effort to get two full benchmarks, I'm sorry :). But I think it went down to the inefficiency of String.split(): https://stackoverflow.com/questions/37007189/string-split-te... and generally the Java's String built-in methods not being GC-friendly: https://stackoverflow.com/questions/20336459/garbage-friendl.... I'm guessing that when such parts can be coded in a non-VM environment (CPython/PyPy runtime) they can be made much faster, and Java to these days has the standard library coded in pure Java?
Re:Show HN: ZFS Implementation in Python by tigershark on Sunday May 05, 2019 @03:40AM (#19831666)
Yes, Java has nothing like C# Span to avoid these kind of problems, but I thought that also python would be affected in a similar way... Anyway, thanks for sharing.
Re:Show HN: ZFS Implementation in Python by auscompgeek on Saturday May 04, 2019 @11:39PM (#19830990)
CPython and PyPy are both VMs, similarly to the JVM.
Re:Show HN: ZFS Implementation in Python by twa927 on Sunday May 05, 2019 @03:38AM (#19831652)
I meant the inside of a VM (its implementation), which is coded in C/RPython. Java's VM is coded in C++, but I don't think C++ is used for any regular library functions, while C is used heavily for Python's stdlib.
Re:Show HN: ZFS Implementation in Python by pjmlp on Sunday May 05, 2019 @05:11AM (#19831877)
Not all JVMs are implemented in C++.

It is a specification with multiple implementations, some of them are even bootstrapped in Java.

Re:Show HN: ZFS Implementation in Python by d0mine on Sunday May 05, 2019 @01:36AM (#19831350)
Re:Show HN: ZFS Implementation in Python by int_19h on Sunday May 05, 2019 @09:04PM (#19836112)
I had a binary parser written in Python that took around 30 seconds on typical input on CPython. PyPy took that down to about 10 seconds. Rewriting it in C# took it down to 200 ms.
Re:Show HN: ZFS Implementation in Python by twa927 on Monday May 06, 2019 @04:08AM (#19837627)
If this was using a loop processing a single byte in an iteration I would expect a greater speedup on PyPy. I've seen 100x speedup in such cases.
Re:Show HN: ZFS Implementation in Python by int_19h on Tuesday May 07, 2019 @12:26AM (#19846576)
Not single byte, but individual fields (float32/int32/string etc). Yes, I expected a much more significant speed-up as well. It's probably because a lot of that code was driven by reflection-type techniques.

Curiously, IronPython did better than anything (but still slow). Haven't tried Jython.

Compiling the whole thing with Cython was less effective than PyPy.

Re:Show HN: ZFS Implementation in Python by twa927 on Thursday May 09, 2019 @08:15AM (#19867516)
Yes, reflection voids many JIT paths in PyPy, AFAIK. Maybe it was worth rewriting the Python code to get rid of the reflection?
Re:Show HN: ZFS Implementation in Python by mehrdadn on Saturday May 04, 2019 @10:13PM (#19830691)
I routinely fail to get speedup on PyPy. In fact I frequently get slowdowns. I imagine it's only fast if your code is slower than it needs to be to begin with.
Re:Show HN: ZFS Implementation in Python by twa927 on Sunday May 05, 2019 @05:29AM (#19831935)
It works well for tight loops processing much data, or heavy object-orientation (multiple levels of class hierarchies). It probably won't work well for regular Django webapps or scripts. Also, real-world Python numerical/AI code uses numpy/ML libs so there's not much to optimize in Python...
Re:Show HN: ZFS Implementation in Python by tanilama on Saturday May 04, 2019 @03:28PM (#19828675)
Only when comparing to CPython
Re:Show HN: ZFS Implementation in Python by fragmede on Saturday May 04, 2019 @05:32PM (#19829521)
pypy is fast, but even were this written in C, there's still the kernel-userland boundary to contend with.
Re:Show HN: ZFS Implementation in Python by moonbug on Saturday May 04, 2019 @06:11PM (#19829710)
Fuse
Re:Show HN: ZFS Implementation in Python by yjftsjthsd-h on Saturday May 04, 2019 @10:46PM (#19830791)
If you're going to run the file system in user space, there's no reason not to just use normal ZFS. The problem with ZFS licensing is only in combining CDDL+GPL in one unit. If you're working across the kernel/userspace boundary, there's already no problem. ZoL even already ships a fuse version that works fine.
Re:Show HN: ZFS Implementation in Python by Conan_Kudo on Sunday May 05, 2019 @01:03AM (#19831269)
> ZoL even already ships a fuse version that works fine.

This is not true. A FUSE implementation is wanted though: https://github.com/zfsonlinux/zfs/issues/8

Re:Show HN: ZFS Implementation in Python by yjftsjthsd-h on Sunday May 05, 2019 @01:45AM (#19831369)
Oops; I didn't realize the existing fuse version wasn't built from ZoL. Thanks for pointing that out.
Re:Show HN: ZFS Implementation in Python by newnewpdro on Saturday May 04, 2019 @01:00PM (#19827684)
Would the CDDL matter for a python implementation that will never become part of the kernel?
Re:Show HN: ZFS Implementation in Python by CaliforniaKarl on Saturday May 04, 2019 @01:29PM (#19827867)
You'd want a reverse-engineering lawyer, so be certain. But my (IANAL) guess is: If this is a proper reverse-engineered implementation, you could then convert _this_ implementation to C, and contribute _that_ into the kernel.

Except, it seems this is BSD-licensed, so I'm not sure how that would work in the kernel (which is GPLv2).

Re:Show HN: ZFS Implementation in Python by loeg on Saturday May 04, 2019 @02:15PM (#19828178)
BSDL code is fine in the GPLv2 kernel. E.g., most of the DRM drivers are dual BSD-GPL licensed.
Re:Show HN: ZFS Implementation in Python by lunixbochs on Saturday May 04, 2019 @02:11PM (#19828146)
BSD is a subset of GPL's restrictions, so you can include BSD-licensed code in a GPL work.
Re:Show HN: ZFS Implementation in Python by loeg on Saturday May 04, 2019 @02:15PM (#19828181)
Subset isn't quite accurate, but "GPL compatible" might be a good way to describe it.
Re:Show HN: ZFS Implementation in Python by dr0verride on Saturday May 04, 2019 @01:19PM (#19827807)
It's clear to me that the solution is to integrate python into the kernel.
Re:Show HN: ZFS Implementation in Python by yjftsjthsd-h on Saturday May 04, 2019 @10:48PM (#19830800)
I assume you mean this as a joke, but I would point out that at least one of the BSD family has gone and baked lua into their kernel. Granted, lua is rather meant for that kind of thing and python isn't, but it is entertaining to point out an interpreted language that has been stuck into a unix kernel:)
Re:Show HN: ZFS Implementation in Python by riffraff on Sunday May 05, 2019 @02:06AM (#19831427)
there was lua in linux too, with lunatik https://github.com/lunatik-ng/lunatik-ng
Re:Show HN: ZFS Implementation in Python by lelf on Saturday May 04, 2019 @01:49PM (#19828000)
Bad title. It’s not a ZFS implementation, so hold your horses.
Re:Show HN: ZFS Implementation in Python by AHTERIX5000 on Saturday May 04, 2019 @05:07PM (#19829387)
What do you mean? Can't you mount & read ZFS filesystems with this one?