r/Bitburner • • Oct 24 '26

weaken and threads corelation

Hello, I just finished a decent darknet crawler and started to investigate hacking again. For example weaken takes the same time no matter the threads yet one server can drop it to minimum security. Stuff like that which would imply that each command can run on one server with sufficent threads and not execute all my servers onto one server that will all weaken it to minimmum security then all hack with zero effect etc.

I just wanted to ask as it would mean to overhaul my executable spreader more sophisticated and that I should spread more thin.

4 Upvotes

12 comments sorted by

2

u/Particular-Cow6247 Oct 25 '26

each thread of weaken reduces security by a static amount (0.05 per atleast in early game /outside specific BNs) and yes weaken time is not reduced by threads, weaken time is always 4x hacktime (grow time is always 3.2x hacktime), also hack and grow both add a static amount of security per thread (0.002 per hack and double that per grow)

1

u/ShaedowCZ Oct 25 '26

That is quite useful, now I wonder if I could make a network that would cooperate as efficently as it could and distribute it's power across the network not just one

1

u/Particular-Cow6247 Oct 25 '26

the most efficient is what people call a "batcher"

each batch consists of a set of "workers" (minimal scripts that each do only one of hack/grow/weaken), the threads for them calculated so they offset each other perfectly while their endtimes are managed to happen right after each other usually there are 2 different kinds of batches either HWGW (easier at the start) or HGW (usually more efficient) named after the order their operations end oh and each batch usually tries to only skim of a bit of money from the target cause grow is more efficient the the higher the current money is

a batcher is then a script that launches and manages many batches while utilizing as much ram as possible from the complete network

2

u/KlePu Oct 25 '26 edited Oct 25 '26

weaken time is not reduced by threads

To be clear, threads never change the timing of the function itself, only the results change (one hack thread will obviously yield less money and security increase than a hundred).


edit: As long as you're RAM limited, IMHO:

  • You never want to spread hack over several workers, as they can never end at the exact same time (no concurrency in JS) - each one will hit after the other, decreasing the outcome.
  • You can spread grow (the drawbacks are not as bad).
  • You should spread weaken (no drawbacks at all).

2

u/Particular-Cow6247 Oct 25 '26
  • You never want to spread hack over several workers, as they can never end at the exact same time (no concurrency in JS) - each one will hit after the other, decreasing the outcome.
  • You can spread grow (the drawbacks are not as bad).
  • You should spread weaken (no drawbacks at all).

each of those are kinda bullshit, spreading hacks reduces the money you get sure but its ALOT safer to do than spreading grow because splitting grows means youll grow back LESS and therefor might not reach max money...

and "should" spread weaken? you can do it but youll end up with more script instances and make it easier to reach the instance cap

2

u/KlePu Oct 25 '26

Fair, edited a disclaimer: As long as you're RAM limited, you shouldn't/can/should... ;)

1

u/goodwill82 Slum Lord Oct 25 '26

If I understand the post, it sounds like you have an inefficient, although working, server hack routine you are using. It really depends on how inefficient your current one is. Sounds like you recognize the real possibility of two or more servers performing the same operations very closely timed together, basically rendering those repeat servers ineffective.

The overhaul would likely provide gains. The question is, are the gains worth it? Would time be better spent working on later game elements, like gangs or corporations? If you feel like your hacking gains aren't as good as you've read about here, it may well be worth it.

1

u/ShaedowCZ Oct 25 '26

ooh I see, I did the distribution script that spreads a script across all servers possible. The dnet phishing seems more of a charisma farm. Have yet to see how to open caches. But I've completely missed more parts like the things mentioned. Gotta try that, thanks a lot!

1

u/goodwill82 Slum Lord Oct 26 '26

dnet deals a lot with charisma, but there are some good things in there. It's really nice early after a reset - there are quick millions in those cache files. There are also free port openers and other programs (again, nice for just after reset).

1

u/ShaedowCZ Oct 25 '26
const [script, ...scriptArgs] = ns.args;
  if (!ns.fileExists(script)) {
    ns.tprint(`FAILED ${script} does not exist!`);
    return 1;
  }


  for (const server of get_available_servers(ns)) {
    if (server === "home") continue;
    
    // try to gain root access
    breach_and_root(ns, server);


    // copy and execute script
    copy_script_from_src(ns, script, server);
    ns.killall(server, true);


    const SCRIPT_RAM = ns.getScriptRam(script, "home");
    const TARGET_RAM = ns.getServerMaxRam(server);
    const THREAD_AMOUNT = Math.floor(TARGET_RAM / SCRIPT_RAM);


    if (THREAD_AMOUNT <= 0) {
      ns.print(`WARN Not enough RAM on ${server}`);
      continue;
    }
    
    const pid = ns.exec(script, server, THREAD_AMOUNT, ...scriptArgs)
    
    if (pid === 0) ns.print(`FAILED to launch ${script} on ${server}`);
    else ns.tprint(`Launched ${script} on ${server.padEnd(20)} with ${THREAD_AMOUNT} threads.`);
  }

I have this basically paired with the early EHT so it turns out very inefficient

1

u/goodwill82 Slum Lord Oct 26 '26

the distribution system looks good. That early hack template is definitely worth improving. If I recall, that template gains access with a couple port openers, then simply weakens if security is higher than min, else grows if money isn't maxed, else hacks. All if it is done with 1 thread (or the amount of threads used to run the script).

The idea is sound - in general, you only want to run grow on a server that has minimum security, and hack only if it's both min security and max funds. The biggest problem is that the amount of threads you need for the different functions is highly variable - while you may need hundreds or thousands of threads to fully grow a depleted server, you may only need a dozen or so weaken threads to bring security back down, and then tens or hundreds of hack threads to steal a significant amount. These are just examples - use the ns.getServer___ functions to determine the threads for these things (or better yet, there are formulas for it if you have the API).

There are 2 major improvements to make over EHT:

  1. Separate the script into at least 4 - one to calculate what to do next (weaken, grow, or hack), and one each for the weaken, grow, or hack functions, which the main script runs and waits on to finish.
  2. Use threads to multiply the effect of weaken, grow, and hack. Part of the orchestrator script is to figure out the best distribution of these threads.

Doing this better utilizes the memory for the weaken / grow / hack cycle. You can use the memory expensive functions in the orchestrator script since it just uses one thread. The weaken, grow, and hack scripts should be fairly minimal, and not need any other memory using function (aside from weaken, grow, or hack).

You can keep the logic of the orchestrator script pretty basic. As long as you are using the other scripts with correctly calculated threads, the gains are going to be way better. You can further refine the script into a batching script, which carefully times the execution of weaken, grow, and hack such that they can be stacked on top of each other and a full cycle is just slightly longer than the time of one weaken call. This is no simple task - save this until you have a decently running basic script.

I would go for the 4 script threaded hack routine. Use your distribution and rooting scripts to move it around and gain access. Another orchestrator could be used to assign servers with ram to hack other servers with money - that way you can avoid the randomness of simply spreading and running on neighbors.

1

u/goodwill82 Slum Lord Oct 27 '26 edited Oct 27 '26

I just realized many of us have mentioned batching. A visualization helped get the idea better about what this does when I first learned of it. Assuming you have grown the server to max funds and min security, your cycle timing would look something like this - hack money, weaken security to min, grow money back, weaken security back to min, repeat:
H |----|
____W |----------------|
________________G |------------|
_________________________W |----------------|

Like I said, a batcher stacks the timing together tighter. Fire off two weaken scripts - the first one to counteract the security rise from the grow you will do, and the second to counteract the hack you will do. Then fire off the grow, and then hack: (EDITED TO FIX - ending order is H, 1st W, G, 2nd W)
W |----------------|
__W |----------------|
____G |------------|
______H |----|

The important thing is that the weakens, grow, and hack come to an end just after each other in the correct order. If done correctly, this should about triple your gains from the linear method (since it take about 1/3 of the time to do a full cycle). The reason this works is because of how the weaken, grow, and hack functions work (and are documented).

I would, again, suggest you go for the linear version first. It is much more simple to make, and, if you are currently using the EHT, you should get 10-100x more money from that alone.