Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrency issues using SES on mono #9

Closed
schourode opened this issue Jan 18, 2013 · 2 comments
Closed

Concurrency issues using SES on mono #9

schourode opened this issue Jan 18, 2013 · 2 comments

Comments

@schourode
Copy link

The listing below shows a simple program which will spawn a number of threads, each responsible for sending a single email via Amazon SES. After delivering its mail message, each thread will print the number of milliseconds elapsed since application start.

var stopwatch = new Stopwatch();
stopwatch.Start();

var mailer = new AmazonSimpleEmailServiceClient(KEY, SECRET);

for (var i = 0; i < THREAD_COUNT; i++)
{
    var thread = new Thread(() =>
        {
            mailer.SendEmail(new SendEmailRequest()
                 .WithSource(FROM_ADDRESS)
                 .WithDestination(
                     new Destination()
                         .WithToAddresses(TO_ADDRESS))
                 .WithMessage(
                     new Message()
                         .WithSubject(new Content("Mono test"))
                         .WithBody(new Body(new Content("Testing 1 2 3")))
                 ));

            Console.WriteLine(stopwatch.ElapsedMilliseconds);
        });

    thread.Start();
}

Console.ReadLine();

Using Microsoft.NET on my Windows machine, it takes around 900 ms to run this program with 1 thread, around 1100 ms with 10 threads, 1400 ms with 50 threads. That's good – it scales great with the number of threads, which is expected due to the amount of waiting involved in calling a web service.

However, when I execute the exact same program on Mono on the same Windows machine, the results a very different. 1 thread: 2 s, 10 threads: 11 s, 50 threads: 62 s. This initially looks like there is a lock() or similar around the HTTP request, effectively forcing sending to be single threaded. Looking closer at the numbers written from the threads, however, all of the threads seems to complete at almost exactly the same time (eg. with 50 threads they all complete between seconds 60 and 62). This seems to suggest some sort of locking behavior, where all of the threads have to wait on the last the finish – weird.

Any idea what this is about? I have a feeling this might be Mono bug, rather than an AWSSDK bug, but I have not been able to reproduce it with "raw" HttpWebRequest instances.

@jakedt
Copy link

jakedt commented Feb 6, 2013

See my answer on this SO post, I believe you could be running into the same issue:
http://stackoverflow.com/a/12371795/1663096

@wmatveyenko
Copy link

Closing as @jakedt has the answer for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants