Questions tagged [concurrency]

In computer science, concurrency is a property of systems in which multiple computations can be performed in overlapping time periods. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors.

Concurrency is a property of systems in which several computations can be in progress simultaneously, and potentially interacting with each other. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors.

A number of mathematical models have been developed for general concurrent computation including Petri nets, process calculi, the Parallel Random Access Machine model, the Actor model and the Reo Coordination Language.

Issues

Because computations in a concurrent system can interact with each other while they are executing, the number of possible execution paths in the system can be extremely large, and the resulting outcome can be indeterminate. Concurrent use of shared resources can be a source of indeterminacy leading to issues such as deadlock, and starvation.

Performance

A common misconception is that increasing concurrency will always improve performance. While it can improve throughput for CPU bound processes by using more CPUs, and I/O bound tasks by amortising the latency of each task, there is many situation where more concurrency hurts performance. Even when it improves performance it can reduce maintainability.

Examples of where concurrency doesn't help

  • The overhead of using multiple threads, exceeds the potential improvement. e.g. You have a very short task, but it takes a long time to pass it (and the data associated with it) to another thread.
    • e.g. the cost of locking a resource exceeds the time taken in the protected operation. A single threaded task might perform much better (and be simpler)
  • You are already using a shared resource to it's maximum extent. e.g. all your CPUs, hard drives, network connection are fully utilised. In this case, the overhead can increase decreasing overall performance.
  • You don't need a performance increase, but adding concurrency increases the complexity of your application. A common argument is; you have to use all your CPUs because they are there (even if there is nothing to gain and everything to lose)

References

22520 questions
10
votes
1 answer

CompletableFuture#whenComplete not called if thenApply is used

I have the following code (resulting from my previous question) that schedules a task on a remote server, and then polls for completion using ScheduledExecutorService#scheduleAtFixedRate. Once the task is complete, it downloads the result. I want to…
kaqqao
  • 12,984
  • 10
  • 64
  • 118
10
votes
4 answers

What is the purpose of the extra result parameter of atomicModifyIORef?

The signature of modifyIORef is straightforward enough: modifyIORef :: IORef a -> (a -> a) -> IO () Unfortunately, this is not thread safe. There is an alternative that adresses this issue: atomicModifyIORef :: IORef a -> (a -> (a,b)) -> IO b What…
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
10
votes
3 answers

Using a pointer receiver in a goroutine

I have a method with a pointer receiver, I was wondering if using this pointer receiver is safe to use inside a goroutine within this method? or should I pass this pointer receiver as a parameter? for example: func (m *dummyStruct) doSomething { …
Keeto
  • 4,074
  • 9
  • 35
  • 58
10
votes
1 answer

Java Google Appengine sharded counters without transactions

I'm going through the Sharded Counters example in Java: http://code.google.com/appengine/articles/sharding_counters.html I have a question about the implementation of the increment method. In python it explicitly wraps the get() and increment in a…
Dougnukem
  • 14,709
  • 24
  • 89
  • 130
10
votes
2 answers

Managing Concurrent Access in a Singleton Session Bean

I got into a discussion with a co-worker about concurrency management in singleton session beans. From my understanding, after reading the Oracle documentation, if you leave off the @ConcurrencyManagement annotation, then it defaults to…
Evan LaHurd
  • 977
  • 2
  • 14
  • 27
10
votes
2 answers

Use multiple tasks to retrieve all records from a large collection

I am working on an application which calls an external service and has to add all entries of the external collection into a local collection. The problem currently is that the external collection can exceed 1000 records, but the returned search…
10
votes
2 answers

How can I use threading in Python to parallelize AWS S3 API calls?

I wrote a Python script that seeks to determine the total size of a all available AWS S3 buckets by making use of the AWS Boto 3 list_objects() method. The logic is simple: Get the initial list of objects from each S3 bucket (automatically…
10
votes
2 answers

Implementing an acquire for a release from Unsafe.putOrdered*()?

What do you think is the best correct way for implementing the acquire part of a release/acquire pair in Java? I'm trying to model some of the actions in an application of mine using classic release/acquire semantics (without StoreLoad and without…
10
votes
3 answers

Is it possible to force request concurrency when using ASP.NET sessions?

ASP.NET does not allow concurrent requests for the same session; meaning that a user can only make 1 request at a time. For example, say we have Test1.aspx: public partial class Test1 : System.Web.UI.Page { protected void Page_Load(object…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
10
votes
2 answers

Java - Semaphore release without acquire

I have threads which are given random number (1 to n) and are instructed to print them in sorted order. I used semaphore such that I acquire the number of permits = random number and release one permit more than what was acquired. acquired = random…
user1474053
  • 103
  • 1
  • 1
  • 6
10
votes
1 answer

what's the difference between Lock and ReentrantLock in Java 5?

I don't understand the difference between them. I thought a lock from the lock interface was reentrant too then what's the difference between them? When would you use each?
10
votes
1 answer

How to get a concurrency of 1000 requests with Flask and Gunicorn

I have 4 machine learning models of size 2GB each, i.e. 8GB in total. I am getting requests around 100 requests at a time. Each request is taking around 1sec. I have a machine having 15GB RAM. Now if I increase the number of workers in Gunicorn,…
neel
  • 8,399
  • 7
  • 36
  • 50
10
votes
2 answers

Do I have to manually stop threads in Java?

When my application is ready to exit, either by closing a window or invoking the System.exit() method. Do I have to manually stop the threads I may have created or will Java take care of that for me?
Dave
  • 7,283
  • 12
  • 55
  • 101
10
votes
7 answers

Thread-ring benchmark

Today I was doing the thread ring exercise from the Programming Erlang book and googled for other solutions to compare. I found that the language shootout has exactly the same problem as a benchmark. I had the impression that this is an area where…
Daniel
  • 26,899
  • 12
  • 60
  • 88
10
votes
4 answers

In C11/C++11, possible to mix atomic/non-atomic ops on the same memory?

Is it possible to perform atomic and non-atomic ops on the same memory location? I ask not because I actually want to do this, but because I'm trying to understand the C11/C++11 memory model. They define a "data race" like so: The execution of a…
Josh Haberman
  • 4,170
  • 1
  • 22
  • 43
1 2 3
99
100