UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » Threads
  • » Performance and mutex locking/unlocking

#1 2008-12-17 12:12 AM

tomcio
Member
From: Poland
Registered: 2006-08-14
Posts: 113

Re: Performance and mutex locking/unlocking

Hi!

Everyone says, that it hits performance very strong, when application performs many mutex locks and unlocks operations. Is it still true nowadays, when we use so fast computers?

Maybe I'll provide an example:

I have function, which sends data over net, we can say, that it's wrapper for stock recv() function. My function performs 4 lock/unlock operation on each execution and it can send 512 bytes at once.  If I'll try to send 20 MB will I notice noticeable performance lose?

Offline

#2 2008-12-17 01:04 AM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: Performance and mutex locking/unlocking

I really doubt you would see much difference... once you start dealing with network I/O, your processing is almost certainly going to be limited by the speed of the the network and not by the speed of your CPUs.

(I suppose if you had a blazing fast network and slow CPUs, there might be an exception to that, but that would be a pretty uncommon situation, I think).

One way to find out would be to try it with and without the locking, and see if you can detect any difference.

-Jeremy

Offline

#3 2008-12-17 08:39 PM

tomcio
Member
From: Poland
Registered: 2006-08-14
Posts: 113

Re: Performance and mutex locking/unlocking

Well good to hear this, because I don't know other way to protect variables in MT applications.

Offline

#4 2008-12-18 04:10 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,204

Re: Performance and mutex locking/unlocking

It's not the locking and unlocking itself that causes performance problems,
It's when lock contention happens and multiple threads need to wait for each
other that things start to fall apart.

(Of course if you have exessive locking then it can be a performance problem.)

Offline

  • Index
  • » Threads
  • » Performance and mutex locking/unlocking

Board footer

Powered by FluxBB