News for hackers. Stuff that matters.
Re:FF4J – Feature Flags for Java by nprateem on Wednesday June 07, 2023 @09:40AM (#36226673)
Having recently kind of abandoned golang for Java, I've got to say I love the richness of the Spring ecosystem.
Re:FF4J – Feature Flags for Java by lbhdc on Wednesday June 07, 2023 @09:44AM (#36226715)
What made you switch?
Re:FF4J – Feature Flags for Java by nprateem on Wednesday June 07, 2023 @10:00AM (#36226871)
I want to create a load of rapid prototypes. With Go it seemed I was wading through treacle just to create a DB-backed REST server that basically just permitted CRUD on the DB with some extra business logic.

With Spring, you just declare a model object and it can infer a data repository with a ton of convention-named query methods, so the number you actually have to write is far fewer. Spring is used by so many people there are loads of good libraries. E.g. I'm just adding permissions, and without needing to hunt around for a compatible library or litter my code with conditionals, it's pretty easy to use Spring Security to configure sane permissions with annotations. With Lombok there's no need to write the garbage you used to have to (loads of getters, setters, etc.) so the code is quite clean.

Annotations also simplify DTOs with mappers - in Go I had this triplicate of model struct, DTO and mapper. Maybe there was a library I could have used to help, but the faff around setting up the DB (e.g writing SQL, configuring an ORM), updating DTOs and mappers was just crippling my velocity.

Plus, for hiring, there are tons of Java devs around the world, while for Go rates are much higher. So yeah, several factors.

Re:FF4J – Feature Flags for Java by lbhdc on Wednesday June 07, 2023 @11:57AM (#36228562)
Thanks for sharing :)
Re:FF4J – Feature Flags for Java by joncfoo on Wednesday June 07, 2023 @01:13PM (#36229857)
Have you come across sqlc? https://docs.sqlc.dev/en/stable/

It gets rid of the crufty parts of DB interaction with Go.

Re:FF4J – Feature Flags for Java by nprateem on Wednesday June 07, 2023 @01:55PM (#36230611)
I did, but didn't end up trying it. Being able to hire a Spring dev for $10 p/h vs several times that for a golang dev (plus time learning a particular codebase) just means it doesn't make sense to use Go if you want to outsource in future.

I plan to run multiple experiments in parallel, keep working the day job and outsource the ones that take off. So the more standardised I can make the tech stack, the faster and cheaper dev work will be.

Re:FF4J – Feature Flags for Java by sgt on Wednesday June 07, 2023 @02:59PM (#36231741)
Being able to hire a decent Spring (or any good developer) at $10 p/h is HIGHLY theoretical.
Re:FF4J – Feature Flags for Java by nprateem on Wednesday June 07, 2023 @05:07PM (#36233588)
Any with any sense will be using chatgpt anyway. It's how I've written most of it. And it's easier to just add to a working project than set one up.

But yeah, we'll see...

Re:FF4J – Feature Flags for Java by victor106 on Wednesday June 07, 2023 @10:26PM (#36236411)
$10 p/h ?

are you joking? if you can find good (I don't want really great) Spring devs for under $80.00 p/h let me know.

You can hire at that rate and everyone I hired had faked their experience and could get through the interview but did a terrible job.

So we ended up firing everyone and had 3 devs for above $110 p/h that were truly awesome who got the job done.

Re:FF4J – Feature Flags for Java by nprateem on Thursday June 08, 2023 @02:07AM (#36237875)
Yeah I'll see how it goes. Tbh at the moment I expect those bottom end devs are worse than just using chatgpt directly. I'll probably have to spend more time explaining to them what I want.

Once IDE plugins can scan the majority of a codebase it'll be easier to just write a bulleted set of requirements and let it get on with it.

But anyway I was talking to a friend who's hired some great Ukrainians quite cheaply and I hear there are some good devs in the Philippines.

Re:FF4J – Feature Flags for Java by nme01 on Wednesday June 07, 2023 @09:51AM (#36226788)
Possible that I was using Spring in a wrong fashion but for me (project size around 300 KLOC) Spring dependency injection model with so much magic happening (all the auto configurations, guessing which classes to load etc.) was extremely hard to maintain and understand. I think I prefer Guice/Dagger style of defining dependencies which is much more explicit.
Re:FF4J – Feature Flags for Java by dtech on Wednesday June 07, 2023 @10:00AM (#36226875)
It's a fair point, although you can set it up to only do explicit defined dependencies which I definitely recommend.
Re:FF4J – Feature Flags for Java by crdrost on Wednesday June 07, 2023 @11:35AM (#36228189)
We had a similar sized project grow out of a 2-pizza-team and had the same problems. Kinda like how Java devs come to JavaScript and are shocked that this language doesn't have proper numerical types, I came to the Java ecosystem and was shocked that everything pivotally hinged on whether you had the right magic beans and especially if you had different beans vying to be the same sort of magic it was awful.

My favorite bug we ran into was a short little RedisConfig.java file that got copy-pasted into a bunch of our microservices in the test environment. It appeared on a very casual glance to connect to Redis. But our tests did not run a Redis instance, so the configuration should have failed. Instead if you looked carefully at this file you could determine that the connection string was all broken but that didn't matter because it never implemented the Redis Connection Bean logic anyway and in fact you could replace it with a purely empty class and tests still pass.

But, tests break when you delete this unused file, the file needs to exist even if it is the empty `class RedisConfig {}`, because now tests are trying to connect to a nonexistent Redis and not succeeding. Same if you try to rename it to like `class RedisTestConfig {}`, suddenly tests want to reconnect to Redis and they all break!! So, everyone has more important things to do, it gets copied to everyone, nobody understands what on earth it is doing since the code inside the file is clearly broken.

Eventually, we start experimenting with Kotlin. When you copy this pattern over to the Kotlin repo, it starts to complain VERY loudly that you have two objects with the same name in the same namespace and it won't start because it is too confused. And that was the key hint. As far as Spring was concerned, this file, because it has the same class name in the same namespace, basically string-replaces that file. (Nondeterministically? Or maybe it was deterministic that "test" won over "main" because it was lexicographically larger?) So we were string-replacing to a RedisConfig that could never be used as a Redis configuration bean, which causes Spring's Redis Cache logic to say "oh I have no configuration, I should assume that I am unneeded", which disables Redis.

But if you rename it, then Spring Redis says "oh I see two things, I can't use that one but I can use this one, let's connect to Redis with that. oh no!! Redis is DOWN!~ crash all the tests!!"

Re:FF4J – Feature Flags for Java by NovaX on Wednesday June 07, 2023 @03:01PM (#36231792)
> Nondeterministically? Or maybe it was deterministic that "test" won over "main" because it was lexicographically larger?)

Java uses classpath ordering for resolution, so a duplicated fully-qualified class name will take the first on the path. This was useful when patching or pre-dependency management, when some library authors would bundle into a fat jar with incompatible versions. It became disallowed by Java 9's modules without command-line flags. It was always considered a bad practices and a natural fallout of the dynamic nature of the JVM. In your case test classes were resolved before main sources and libraries.

Unfortunately there is a broad view that Java == Spring. In over 15 years of full time Java development, I only used Spring Framework 1.x and 2.0 (migrating from pre-DI). Since then my employers and network all used Guice, though I never selected a role where I realized that choice upfront. That framework is far less magical and explicit, making it very easy to debug. I suppose tool popularity is regional, it's just that this type of Spring magic is abnormal and disliked throughout my work experience.

Re:FF4J – Feature Flags for Java by tivert on Wednesday June 07, 2023 @12:06PM (#36228718)
> Possible that I was using Spring in a wrong fashion but for me (project size around 300 KLOC) Spring dependency injection model with so much magic happening (all the auto configurations, guessing which classes to load etc.) was extremely hard to maintain and understand. I think I prefer Guice/Dagger style of defining dependencies which is much more explicit.

Spring used to be (and still can be) very explicit about defining dependencies, but they've been pushing more towards encouraging the use of "magic" over the last many years. I prefer to be as explicit as possible about everything, unless I have a very good reason not to be, and tend to either specify the literal bean name in the annotations or use the older XML-style configuration (and do the same).

Re:FF4J – Feature Flags for Java by the_doctah on Wednesday June 07, 2023 @01:07PM (#36229739)
You don't need to use Spring Boot (which does all of the opinionated autoconfig). Just import the Spring components that you need.
Re:FF4J – Feature Flags for Java by ye-olde-sysrq on Wednesday June 07, 2023 @10:07AM (#36226951)
One thing that bothers me about Spring is how it manages to use so much off-heap.

I used it initially for a small project (hobby-tier) and was shocked to find it was using 200-300MB of offheap (or something in that range). To where my poor 1GB RAM digital ocean VPS was 20-30% just random Spring offheap crap.

I ported my handlers from Spring to just using netty and their provided HTTP codecs (and I wrote my own http router implementation which was fun but also wish there was an easy one to just use, I didn't see anything I liked when I looked) and suddenly offheap was ~0 and I could've easily crammed 100 of these into this tiny VPS. (Not that I planned to, but I did want to use this VPS for other things too).

I know "300MB offheap" is not something Spring will care about when they're probably normally running on giant ec2 instances, but for my case, while I would've liked to use the "django/rails but for java"-type tool, it did actually end up being too heavy in the most-constrained vector of cloud hosting (RAM).

Re:FF4J – Feature Flags for Java by nunobrito on Wednesday June 07, 2023 @10:42AM (#36227381)
Of course that all depends on the context, for my cases I'll certainly keep my distance from either Spring or JBoss. Prefer to build faster apps with Java.
Re:FF4J – Feature Flags for Java by frant-hartm on Wednesday June 07, 2023 @11:08AM (#36227772)
Not sure what you did wrong. You can easily fit whole spring web app including support for jpa and what not into 300 MB heap/native together.
Re:FF4J – Feature Flags for Java by throwaway45391 on Wednesday June 07, 2023 @11:30AM (#36228114)
I'm not an expert, but I think the memory used is not necessarily the memory it requires.

I think Java tends to grow memory usage up to a point, rather than to try and release it at the cost of performance. That doesn't mean it would not be able to run on a machine with lower memory. It could run more expensive GC if it was needed

Re:FF4J – Feature Flags for Java by mrkeen on Wednesday June 07, 2023 @12:32PM (#36229207)
I have been told this before too.

Currently I can't run my integration tests on my work laptop because they spin up a bunch of "micro" services, so I run out of ram and need to reboot.

The memory that Java "doesn't require" really adds up.

Re:FF4J – Feature Flags for Java by Pet_Ant on Wednesday June 07, 2023 @02:09PM (#36230846)
I believe that is why the original Java answer to microservices was EARs all within a single app server so they could share a JVM and caching. Then in production for load you could spread them all out and they can find eachother... but I've never worked in actively developed JEE (as opposed to a legacy one).
Re:FF4J – Feature Flags for Java by imtringued on Thursday June 08, 2023 @02:07PM (#36246113)
It's especially bad when you have to run both IntelliJ with multiple projects and grails.
Re:FF4J – Feature Flags for Java by seadan83 on Wednesday June 07, 2023 @01:10PM (#36229797)
Java by default allocates a healthy percentage of available RAM. It releases memory if a large percentage is unused, and it only runs full GC when a large percentage is used. The trick is therefore to decrease the initial max memory. Otherwise you can wind up with 70% usage, a lot of objects that could be GC'd but are not because there is not enough memory pressure to run full GC, and there is not enough unused memory to be able to release RAM back to the OS
Re:FF4J – Feature Flags for Java by ye-olde-sysrq on Wednesday June 07, 2023 @01:59PM (#36230676)
See my reply to the other comment - I specifically refer to off-heap memory, not on-heap/GC-managed memory.
Re:FF4J – Feature Flags for Java by ye-olde-sysrq on Wednesday June 07, 2023 @01:58PM (#36230664)
I'm here specifically referring to off-heap memory. I verified this by looking into the jvm with VisualVM. These are objects that aren't part of the normal java heap area and aren't part of garbage collection. The offheap can contain many things - classloaded code, memory-mapped files, direct bytebuffers, and so on. And since it's offheap, it's hard to analyze from Java tooling. So I literally don't know what it was doing.

So in my above scenario, I could indeed run the app with a -Xmx32M and yet the application was still using 200-300MB of resident memory (RSS) due to offheap usage.

Re:FF4J – Feature Flags for Java by NovaX on Wednesday June 07, 2023 @02:48PM (#36231560)
You can use native memory tracking to better inspect offheap usages. I had a similar problem where the default MaxMetaspaceSize was excessive and adjusted it to a reasonable setting.

-XX:NativeMemoryTracking=summary

jcmd <pid> VM.native_memory summary

Re:FF4J – Feature Flags for Java by imtringued on Thursday June 08, 2023 @02:05PM (#36246086)
I am sorry but RAM is the least constrained vector of cloud hosting. I have apps that need to do video encoding in real time with 100ms latency and those are always bottlenecked on CPUs.

I have a micronaut app that uses around 350MB which is almost entirely JVM overhead.

Re:FF4J – Feature Flags for Java by sgt on Wednesday June 07, 2023 @11:35AM (#36228207)
What is wrong with Go?
Re:FF4J – Feature Flags for Java by bern4444 on Wednesday June 07, 2023 @12:27PM (#36229106)
it should have been named stop cause you have to stop at every function call to check for an error.
Re:FF4J – Feature Flags for Java by kaba0 on Thursday June 08, 2023 @05:29AM (#36239245)
That it has the expressivity of Java.. from 20 years ago.
Re:FF4J – Feature Flags for Java by sgt on Thursday June 08, 2023 @07:48AM (#36240282)
In theory it's a good Python alternative if you want more speed. But having done a bit of Go, I tend to agree. Developing in Go can be frustrating.

Java these days is however looking much better.

Re:FF4J – Feature Flags for Java by mikro2nd on Wednesday June 07, 2023 @11:51AM (#36228475)
Realy? I saw "Spring", suddenly acquired a skin rash, and swore I'd never look at this again...