Skip to content
This repository was archived by the owner on May 10, 2018. It is now read-only.
This repository was archived by the owner on May 10, 2018. It is now read-only.

Threading questions #3

Closed
Closed

Description

@supermihi

Hi,

I am trying to understand how WampSharp uses threads / how it can be used in multii-threaded applications, but fail to find any documentation on that issues. To be specific, the following questions remain open so far:

  • Is it safe to use a channel from multiple threads as a caller (using e.g. GetCalleeProxy?
  • When I register a callee, is the method it defined always run in a separate thread? If, for example, it takes 5 seconds to compute, and two callers call it simultaneously – will it take 5 seconds or 10?
  • How does this behavior depend on whether the callee's WampProcedures are defined as returning a Task<resultType> instead of <resultType>?

Thanks in advance!
Michael

Activity

  1. darkl commented on Apr 29, 2016

    @darkl
    Member

    Hi Michael

    Regarding your questions:

    • using a WampChannel should be thread-safe.
    • This depends whether the method is synchronous (i.e. doesn't return a Task) or asynchronous (returns a Task). In the first case, the method blocks the WebSocket loop, and other requests can't be handled. Therefore it will take 10 seconds to complete both requests in this case. In the latter case, where the method returns a Task, the Task is awaited. In this case, once the task is returned, the WebSocket loop is no longer blocked and further requests are processed.

    Elad

  2. supermihi commented on May 4, 2016

    @supermihi
    Author

    Hi Elad,
    thanks for your response. That means, if I want to register methods (callee) that might take some time, I should follow the pattern?

    [WampProcedure("com.example.test")]
    public async Task<TResult> Test()
    {
        await Task.Run(() => ExpensiveOperation());
        // stuff to evaluate the result
        return result;
    }
    

    Michael

  3. darkl commented on May 4, 2016

    @darkl
    Member

    Hi Michael,

    Something like that. You should manage yourself the number of tasks you want to run in parallel. You can use some threading mechanism such as TPL.Dataflow (ActionBlock and etc) in order to have better control on the number of tasks running in parallel.

    Best regards,
    Elad

  4. supermihi commented on Nov 8, 2016

    @supermihi
    Author

    Hi Elad,
    just found that this issue is still open – closing it as everything works very well for me, including sharing a client between several threads. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions