Open Closed

Does unit of work lock tables/records? #4454


1
sparkyjr created

Hi,

We are experiencing a very slow performance when there are as less as 10 users using our site.

We have a strong feeling that the tables/records are getting locked, and are not available for other users. Because, unit of work is like a transaction, am I correct?

Does unit of work lock tables/records? Does it lock tables/records even if the method is just fetching data?

Thanks in advance, SparkyJr


7 Answer(s)
  • 0
    bbakermmc created

    SQL profiler should be able to tell you whats being locked. You could also set your context to pull dirty data if you dont care.

  • 0
    ismcagdas created
    Support Team

    Hi @sparkyjr,

    Yes, it locks tables even for the read operations but your problem might be different. Can you share which version of ABP framework you are using ?

  • 0
    sparkyjr created

    We are using Abp Version=0.8.3.0

  • 0
    alper created
    Support Team

    hi,

    for the only SELECT queries you can disable transaction to improve performance.

    A unit of work is transactional as default (by it's nature). Thus, ASP.NET Boilerplate starts/commits/rollbacks an explicit database-level transaction. In some special cases, transaction may cause problems since it may lock some rows or tables in the database. In this situations, you may want to disable database-level transaction. UnitOfWork attribute can get a boolean value in it's constructor to work as non-transactional.

    Example usage:

    [UnitOfWork(isTransactional: false)]
    public GetTasksOutput GetTasks(GetTasksInput input)
    {
        var tasks = _taskRepository.GetAllWithPeople(input.AssignedPersonId, input.State);
        return new GetTasksOutput
                {
                    Tasks = Mapper.Map<List<TaskDto>>(tasks)
                };
    }
    

    Further information: <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#non-transactional-unit-of-work">https://aspnetboilerplate.com/Pages/Doc ... it-of-work</a>

  • 0
    sparkyjr created

    Thanks Alper for your reply!

    So, in short, we need to disable unit of work for the entire flow, right? Like from controller action to the app service methods, right?

    Are there any known issues if we disable unit of work?

    Regards, SparkyJr

  • 0
    alper created
    Support Team

    just disable transaction. no need to disable whole UnitOfWork. And do it in the AppService method. If you are using MVC do it in Controller action.

  • 0
    sparkyjr created

    Thanks Alper!

    We will apply this attribute on the controller actions then:

    [UnitOfWork(isTransactional: false)]

    Regards, SparkyJr