Tag Archives: Concurrency

future of Python: Concurrency devoured, Node.js next on menu

Future of Python: Concurrency devoured, Node.js next ?

Java? Are you serious ?

https://www.theregister.co.uk/2017/08/16/python_future/

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Important review of C++ Concurrency in Action Book review for potential HFT

 

Crucial review of C++ Concurrency in Action Book review for potential HFT

I did a lengthy review on the various options of C++ concurrency libraries you can use. Out of all the libraries I played with, I think the Standard C++ Threading library  is your BEST option as it is not considered a dependency. When you factor Intel Threading Building Blocks, I found it somewhat disappointing to use with their Flow Graph tool which is supposed to make your coding much easier. It only generated C++ code that could not be compiled. Good luck in trying to decipher it as well.

With this decent book, I got a better handle on the Standard C++ Threading library which gave me proper foundation in how to build out a high speed algorithm trading system. There are so many items to consider which this book covers. As a result, I made a 30+ minute video describing what is entailed in understand the importance of multi-threading in a C++ environment.

Check out my 30+ minute video here

 

How to build source for C++ Concurrency in Action

One big weakness I found with this book is that the coding samples were not complete. I was fortunate enough to find a GitHub repository which showed how to use the coding samples in this book.

Watch my video tutorial here

I would also like to mention I am thinking of doing a variety of ‘make up classes’ to make up for the missed tutorials in my Future/Options strategy. This includes critical topics of:
Optimal Hedging
Options on futures    
Options examples continue
Additional Options concepts with comparison to Futures    
Option pricing more examples    
Call put parity
Options trades

Coding samples will be offered in a combination of Python and C++.

I will need to do this on a Saturday only so I am trying to find out if those want it on Jan 14 or Jan 21. This will need to start early 9AM EDT.  Let me know what works for you.

This will be available to all my Quant ELITE members.

Not a member, join now!

Thanks Bryan

P.S. If you are interested in this mini workshop, I would strongly recommend to jump on this AS SOON AS POSSIBLE to properly prepare for these topics if you are unfamiliar with them.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

How to build source for C++ Concurrency in Action

How to build source for C++ Concurrency in Action

Finally go this work for less experts more newbies

Use this repo https://github.com/subjam/concurrency-in-action

DO NOT use this repo https://github.com/iZhangHui/CCiA

Crucial review of C++ Concurrency in Action Book review for potential HFT

Join my FREE newsletter to learn more about this helping in your automated trading

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Crucial review of C++ Concurrency in Action Book review for potential HFT

Book review CPP Concurrency in Action

I will have a video to explain this useful book

http://moodycamel.com/blog/2013/a-fast-lock-free-queue-for-c++

https://www.amazon.ca/C-Concurrency-Action-Practical-Multithreading/dp/1933988770#reader_1933988770

https://www.manning.com/books/c-plus-plus-concurrency-in-action

https://github.com/iZhangHui/CCiA

Join my FREE newsletter to learn more about how concurrency impacts your automated trading

 

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

C++ Concurrency book learning without TBB?

C++ Concurrency book learning without TBB?

With the strange errors I am getting as described here

http://stackoverflow.com/questions/41418733/tbb-c-multithreading-error-no-matching-function-for-call/41418828#41418828

I found the nitty gritty code that is generated from the TBB Flow Graph is quite cumbersome. It is also buggy where it cannot compile. I went back to the drawing board to take a look at this book. Flow Graph has also been listed as being in Alpha mode.

https://software.intel.com/en-us/forums/flow-graph-designer/topic/594239

https://www.amazon.ca/C-Concurrency-Action-Practical-Multithreading/dp/1933988770

It has been recommended by various sources so I read it now.

Something else to consider I just found:

http://stackoverflow.com/questions/17252402/intel-tbb-its-2-time-slower-than-std-tbb-vs-std

is this another blessing in disguise??

Book useful code snippets:

2.8, 3.4, 3.8

3.11-3.12

4.1, *4.5, 4.9, 4.10,

5.10, 5.11

6.2, *6.6, 6.7 -6,13

Lock free for all 7

*7.13 start of  lock free queue

8.5, 8,7, 8.8, 8.11, 8.12

9.1-9.4 (threading pools), 9.6-9.9

Also, these skills are top paying where most are C++ low latency multithrading.

http://www.hrg.net/job-listing/?category_id=3

75% approx at top end vs rest maybe for Java

Join my FREE newsletter to learn more about how ++ multithreading is important for automated trading

 

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Demo of C++ Redis NOSQL Intel TBB concurrency together

Demo of C++ Redis NOSQL Intel TBB concurrency together

This could be the blueprint for my upcoming C++ trading systems

Join my FREE newsletter to learn more about when I release this code for all my Quant Elite members

Please watch these videos before the last one which is the overview of this code:

 

Most recent milestone code with Redis and Intel TBB working together

 

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Concurrency tips for C++ 14

Concurrency tips for C++ 14

This includes lock free approaches as well

https://www.justsoftwaresolutions.co.uk/threading/new-concurrency-features-in-c++14.html

Join my FREE newsletter to see how I will apply C++ into my automated trading

 

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

See how Stroustrup wants next C++ goals: Parallelism, concurrency

See how Stroustrup wants next C++ goals: Parallelism, concurrency

It is even good enough for me wanting to becoming an eventual master of this even more powerful language. Even C++14 will have lambdas just like Java or C#.

http://www.infoworld.com/article/2840344/c-plus-plus/stroustrop-c-goals-parallelism-concurrency.html

Join my FREE newsletter to learn more about this powerful language for true quant algo development

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

How to use Microsoft AMP for Windows concurrency with Fast Math using Visual Studio 2012 and C++

How to use Microsoft AMP for Windows concurrency with Fast Math using Visual Studio 2012 and C++

UPDATE:  C++ AMP is slowest compared to CUDA http://codinggorilla.domemtech.com/?p=1135

Here is a decent description of AMP:

http://msdn.microsoft.com/en-us/library/vstudio/hh265136.aspx

Here are the support Fast Math functions for AMP:

http://msdn.microsoft.com/en-us/library/vstudio/hh553048.aspx

Note that need Windows Server 2012 or Windows 8 to use GPU debugging preview in Visual Studio 2012

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Java Concurrency Question for Quant Development

Java Concurrency Question for Quant Development

In November 2009 I went to No Fluff Just Stuff. One of the presentations was by Brian Goetz, which was about Java concurrency. For some reason there were items on his agenda slide that were not covered in his presentation.

He went over some strategies, and at the end he pointed out a common tactic that he also said is a good rule of thumb for concurrency in Java: Make your variables private, and make any methods that access them synchronized.

That sounds pretty simple. And perhaps too good to be true. Are there situations/applications where this concurrency technique would not be sufficient? Would relying primarily on this technique work well in systems with lots of transactions, or large data sets? What are the potential drawbacks of doing this?

 

Key design philosophy is to to minimise mutability and document the locking strategy for what’s left

• This strategy is thread safe but in systems with lot of transactions, it will not scale since synchronizing methods has over heads and results in some slowdown of the application

In a nutshell, keep your critical sections small and have a clear idea of dependencies between different threads to avoid deadlock

Now that multicore processors are now pretty standard, when lock collision is expected to be low, it is better to use a spinlock than a conventional critical section synchronised function. Using a spinlock (java.util.concurrent.atomic) or the higher-level ReentrantReadWriteLock will minimise the serialisation when threads contend for access to the critical section.

The best strategy though is keep objects immutable and version when objects do need to mutate.

: What about using locks? Or synchronizing on objects within methods. Is there less overhead for that? I know that limiting mutability is good, but I am just trying to explore the topic further.

 

 

Re exploring the topic, start with “volatile” (un-optimized vars), move to “atomic” (relying on relevant CPU instructions), next will be “ReadWriteLock” (exclusive write ops, un-blocked read ops when there are no write ops) and finish with “synchronized” (everything is exclusive). On top of that, have a look at the Actor concepthttp://drdobbs.com/high-performance-computing/229402193

Threading models are domain specific; in what I do, a small number of threads with minimal contention is most desirable.

I would be very careful of things like volatile and atomic. Go for correctness first and optimise later. I would also avoid explicit use of spin locks: any OS worth its salt will use adaptive mutexes anyhow (which are spin locks unless it makes sense for them not to be).

If you can bear it, read through the java memory model which is available on the web. The guarantees are actually quite loose. You need to consider atomicity but also visibility and ordering.

If you’re seeing performance problems with a multi-threaded program, I reckon a look at the broader design will yield more benefits than swapping out synchronized for volatile / atomics etc

Over time, I have had similar architectural problems with C, C++, Java and C#, and, besides the differences on the what each language allows and does not allow to do, on all cases, the conceptual solution has turned out to be the same:

You have to find ways to enqueue the concurrent changes to the state of an object, no matter the language, platform, whatever: no matter how you slice it.

You have to make sure that only your object has access and control of its own state, but that is not enough in a multi-threading environment.

You could use any sort of synchronizing strategies for your concurrent (multi-threading) changes, as much as your platform and tools allow.

You could have a Singleton in charge of invoking the actual changes to the state of objects, will the threads are able to call some method or event handler of the Singleton.

It is a general, ok solution to add synchronized to methods as it will ensure sequential consistency (what a thread sees is the latest state and not stale version as writes are flushed to memory and not local caches). However prefer lock splicing and lock-free (compare and swap) algorithms over using synchronized methods; also it depends on the use of synchronised, how many invariants need to be guarded, the number of threads reading and writing to the data structure and what level of sequential consistency is needed. Use synchronization with judicious caution if you care about performance where milliseconds count; especially if you are guarding multiple, independent invariants with synchronized methods as performance will degrade quickly especially when there is significant throughput.

Let me give you a concrete example by comparing Hashtable and ConcurrentHashMap. The former uses synchronized methods for each method invocation and the latter uses lock splicing (each bucket has its own lock). Which one provides better performance? ConcurrentHashMap – by far!

Why? ConcurrentHashMap uses a mixture of volatile variables (ensures reads and writes are to memory and not CPU caches), lock splicing (each hash bucket has its own lock) and lock-free reads. It enables vast amounts of threads to read and write at the same to the data structure in parallel (of course, assuming the hashing exhibits uniform distribution among the buckets!). Hashtable only lets one thread access the data structure at a time and there is overhead cost to acquire and release the lock; if there are many threads wanting to read and write and lots of entries then each one has to wait for access; just imagine being at at airport with hundreds of passengers and only one check-in desk! However there is a downfall to using ConcurrentHashMap as it doesn’t provide sequential consistency (when you do a read operation, it will retrieve the latest write value) as the reads are lock-free; if a read and write happens at the same time the write operation may note be visible to read. In performance critical systems, most developers will prefer performance over sequential consistency.

True. It is also worth mentioning about “optimistic locking” (at which point “atomic” operations are very useful). And I agree with James Taylor that one thread per CPU/core is the best configuration (in order to reduce “context switch” effect).

Few more terms to explore “executors” (from “concurrency” package, e.g. “Executors.newFixedThreadPool(…)” static method) and “Selector” (from NIO, allowing one thread to control multiple I/O ops)

The Java Concurrency is pretty big and complicated theme. Check following link
http://www.ebook3000.com/Java-Concurrency-in-Practice_1736.html

 

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!