Hey, on a large wallet I have noticed, that *NioClientManager* thread does 
a lot of CPU computation, and meantime other Wallet functions are 
unresponsive (possibly because of locking). No need to mention, that one 
thread = once CPU core to do the work.
Is it possible to parallelize this thread work?
One thing I thought would help - compute double spends in parallel.
Quick update and test I did was: updated bitcoinj to support java 8 (as I'm 
not an expert in Java 6 threading), and trying to parallelize 
*findDoubleSpendsAgainst 
*method.

private Set<Transaction> findDoubleSpendsAgainst(Transaction tx, 
Map<Sha256Hash, Transaction> candidates) {
        checkState(lock.isHeldByCurrentThread());
        if (tx.isCoinBase()) return Sets.newHashSet();

        final Set<TransactionOutPoint> outpoints = 
tx.getInputs().stream().map(i -> i.getOutpoint()).collect(Collectors.toSet());

        final Set<Transaction> doubleSpendTxns = Sets.newConcurrentHashSet();
        candidates.values().stream().parallel().forEach(
                c -> {
                    c.getInputs().stream()
                            .filter(i -> outpoints.contains(i.getOutpoint()))
                            .forEach(o -> doubleSpendTxns.add(c));
                });

        return doubleSpendTxns;
    }


Maybe it can be optimized even more, but at this point *NioClientManager* 
thread, together with new *ForkJoinPool* threads, consume all of the CPU 
cores and does their work x(core count) faster!
Still this is only one method I have updated, I think this can be extended 
to use CPU better.
What would be the comments about this approach and implementation on 
bitcoinj master for Java 6?

Thanks,
Justas

-- 
You received this message because you are subscribed to the Google Groups 
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to