Friday 15 June 2012

c# - Is there any performance gain when using async in Data Access Layer? -



c# - Is there any performance gain when using async in Data Access Layer? -

i have uncertainty there performance gain if utilize async feature in info access layer below :

public async task<ienumerable<trnapplicant>> getallmemberapplicantsasync(string webreferencenumber) { using (var context = new onlinedatacontext()) { var applicant = await task.run(() => context.applicants.first( app => app.refno.equals(webreferencenumber, stringcomparison.ordinalignorecase)) ); homecoming getapplicantsingroup(applicant.applicantsgroupid); } }

also if not when create more sense?

consider this.

you phone call , inquire them you. while it, wait on line, waiting them "it's done". synchronous work. deed of calling them "blocks" until they're done job, , can whatever doing, afterwards.

the alternative, asynchronous way, create call, instead of waiting on phone hang up, , else while work. 1 time phone call back, saying "it's done", go doing whatever needed results do.

now, if have nil do while wait, there absolutely no performance gain, instead quite opposite. overhead of having other party phone call instead add together total amount of work do.

so above description of asynchronous work, have code while waits info access layer finish job?

if not, no, there no performance gain.

if yes, there performance gains.

now, having said that, read comment below answer, , re-read code bit more carefully, , believe not taking advantage of proper asynchronous code here.

the best way utilize kind of scheme or code asynchronous i/o properly. code calls task.run, same plunking different person downwards in front end of phone, doing waiting you.

for instance, consider sqlcommand, may actual code doing talking database here, has 2 interesting methods:

sqlcommand.executereader sqlcommand.beginexecutereader

now, if phone call first one, on thread created task.run, in effect still blocking, you're asking else you.

the second, however, described above.

so in particular case seek avoid using task.run. now, depending on load of server, there may advantageous that, if can switch using asynchronous methods of underlying objects properly.

c# asp.net-mvc asp.net-mvc-4 asynchronous c#-5.0

No comments:

Post a Comment