Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Che Delilas
Nov 23, 2009
FREE TIBET WEED

Ciaphas posted:

ReSharper, I vaguely remember the dev team I'm helping was working on getting that, I think. I'll have to look at what it is, I've never heard of it, but if it helps me deal with bullshit boilerplate like that Equals stuff (thanks for that by the way) I'm all for it :v:

I hate Resharper every time I type a period and continue typing and it lags JUST long enough for Intellisense to not kick in at all for the remainder of the symbol unless I go back and type the period again.

But I love Resharper every time I ctrl-t.

Adbot
ADBOT LOVES YOU

Funking Giblet
Jun 28, 2004

Jiglightful!

Sedro posted:

You need to implement GetHashCode, and yours will throw exceptions when comparing to null.

You shouldn't be writing this boilerplate. Here's what R# generates:
C# code:

class Request : IEquatable<Request>
{
    public string FileName { get; set; } // whatever

    public bool Equals(Request other)
    {
        if (ReferenceEquals(null, other)) return false;
        if (ReferenceEquals(this, other)) return true;
        return string.Equals(FileName, other.FileName);
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        if (obj.GetType() != this.GetType()) return false; //Here be dragons

        return Equals((Request) obj);
    }

    public override int GetHashCode()
    {
        return (FileName != null ? FileName.GetHashCode() : 0);
    }
}
You can also use compile-time instrumentation (e.g. Fody) which is a bit more maintainable than code generation

The comparison I highlighted above can caused issues with dynamic proxies, so ensure either you skip it, or unwrap the proxy before comparison.

Sedro
Dec 31, 2008
It's best not to mix inheritance with custom equality anyway. Make the class sealed and get rid of the comparison.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


The class in question already overrides ToString() using all of its members; would overriding GetHashCode to return ToString().GetHashCode() be an okay thing to do or is that a faux pas?

epswing
Nov 4, 2003

Soiled Meat

Back from several business trips, sorry for the delayed responses!

Essential posted:

Unfortunately I can't provide any help on your current situation, however I can tell you that I pay the $30 per month support fee for 1 of my azure accounts and I can say the help was tremendous the 2 times I've needed it.

I decided to bite the bullet and purchase developer support. When I try to open a support ticket, I'm asked to choose a subscription, and developer support isn't in the list. If I choose my BizSpark subscription, I'm asked to choose a support plan, and developer support isn't in the list. Now what.

RICHUNCLEPENNYBAGS posted:

Well, I'm using Azure SQL and Azure Web sites at work and haven't experienced that, so I think there's something about your instance or setup in particular that's defective.

How on earth would I go about solving such a problem while the app is live?

Bognar posted:

Ditto this, I haven't had the SQL transient exception more than once a month, and I haven't seen it at all since we used the SQL Azure Execution Strategy. What region are you using?

Am I the only one who thinks "well it only happens once a month" is unacceptable?

My resources are all in East US.

Fiedler posted:

Are you using Azure SQL DB V12?

Yes.

EssOEss posted:

I can confirm that I experience the same type of random interruptions multiple times a day. 10 GB database, quite low load (average 1 request per second). Funny thing is that SqlAzureExecutionStrategy does not catch all of the random errors! We had to add some custom retry logic on top for whatever reason, to really make it retry on all the retry-worthy cases.

Overall, though, going the retry logic route has worked fine for us. It is a bit disconcerting coming from an oldschool "What do you mean it goes down arbitrarily?!" perspective but I suppose it's a good way to ensure the app is fault tolerant :)

The limit on manual transactions has not proven to be an issue so far, since I have taken care not to introduce any to the application. Perhaps you can re-engineer your app not to require them?

Re-engineer my application because Microsoft doesn't like transactions? What??

:derp:

Sedro
Dec 31, 2008

Ciaphas posted:

The class in question already overrides ToString() using all of its members; would overriding GetHashCode to return ToString().GetHashCode() be an okay thing to do or is that a faux pas?
You probably could... as long as your toString doesn't include any extra information which is not part of the equality, and you don't change the locale, and you can spare the cycles/GC pressure. Really there is no reason to be cute like that. Implementing a hash code wrong has subtle and dangerous implications.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Fair enough! I'll be sure to do it properly. Thanks again :)

Essential
Aug 14, 2003

epalm posted:

I decided to bite the bullet and purchase developer support. When I try to open a support ticket, I'm asked to choose a subscription, and developer support isn't in the list. If I choose my BizSpark subscription, I'm asked to choose a support plan, and developer support isn't in the list. Now what.

I just tried this and was able to get there by doing this:

Log into windowsazure (this is the old portal). Select username from top-right, select Contact MS Support (this now redirects to the new azure portal: portal.azure). Select Create Support...On step 4 choose Additional Options from dropdown and below the BizSpark Access ID/Contract ID there should be a link "Purchase support plan". When I click that link I see the different support plans, Developer being one of them.

Iverron
May 13, 2012

Kekekela posted:

And yeah, code comments and other largely ceremonial things seem to be for some reason the trappings that new developers associate with "good code" that are in fact (usually) the opposite.

It was parroted in a really poor way throughout my CS education. I imagine that has a hand in why so many developers prefer the kind of commenting from a few pages back.

Tony Montana
Aug 6, 2005

by FactsAreUseless

Iverron posted:

It was parroted in a really poor way throughout my CS education. I imagine that has a hand in why so many developers prefer the kind of commenting from a few pages back.

Yeah as I don't have a formal, modern CS education and I'm a bit oldschool (in my 30s) I guess I've picked up commenting along the way. If it's an outdated concept, then that is something this thread has taught me :)

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Just to confuse you even more: well-commented code is a good thing, but good comments are not what most people think they are.

SirViver
Oct 22, 2008

ljw1004 posted:

* Occasional unexplainable sluggishness/hangs in opening Extensions&Updates, opening NewProject, ToolsOptions -- for these again, if you have time, it'd be great to "send a frown". We haven't had any other reports of these kinds of hangs yet.
Welp, sent two reports for this a few minutes ago after I had managed to reproduce it, but of course, once I start the recording tool and open the dialog it magically works :(

I'll see if I can properly reproduce it later, I hope you don't mind the duplicate reports - I tag all of them with the attention thing you mentioned.

E: Also sent a report regarding the EnC hang.

SirViver fucked around with this message at 08:59 on Jul 31, 2015

Mr Shiny Pants
Nov 12, 2012
hahaha It's Alive!

So I decided OpenXML would not get the best of me and I finally did it!

With judicious use of the Productivity Tool I can finally create my reports the way I want them.

It has:

Nicely styled tables with a nice colored header and odd even row colors, styled headers, Auto Table of contents, right sized pictures and hyperlinks to various parts in the document all generated from a JSON file which my RT app generates.

Phew. Thanks for your moral support!

Weekend! :)

Essential
Aug 14, 2003
One of my apps uses a third party REST api and they've recently implemented a 5 requests per second limit. We're hitting that limit a lot mostly because we have 15 systems spread out across the US and some of them run at the same time (each one fires off about 25 requests). So while an individual account doesn't have the issue, when 5 run at the same time it becomes a problem. Currently we use HttpResponseMessage to send the request async and await the result. The requests do not come from the client, but from an azure cloud service. The clients send an alert to the cloud service, which then builds & sends the requests on behalf of the client. This is fire-and-forget, the clients do not need to know the response.

I'm guessing that we need to implement a queue system for this? We have an azure account, so 2 queue systems are available (Queue Storage and Service Bus Queue). The queue will only be for these requests so I'm not worried about multiple apps being able to subscribe. Or maybe this isn't a good implementation for a queue and instead there is something else we should do? Maybe we can use the existing cloud service and implement rate limiting on it?

Whatever we come up with needs to be fair to their servers, so we can't retry over and over until it goes through. We want to make sure that we're being responsible on our end and eliminate any unnecessary calls to their server.

Anyone have any advice/direction?

Essential fucked around with this message at 16:52 on Jul 31, 2015

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Assuming these 15 systems are expecting some sort of response from that server, then I don't think a queue is a great thing to use. If what you're doing is more fire-and-forget then a queue would be fine.

My immediate thought is to set up a proxy server for the API. Your servers make requests to the proxy, it forwards the requests on to the API but also rate limits itself.

The other option is to get on the phone and see if you can work something out with the API provider so you have a higher limit.

Essential
Aug 14, 2003

Bognar posted:

Assuming these 15 systems are expecting some sort of response from that server, then I don't think a queue is a great thing to use. If what you're doing is more fire-and-forget then a queue would be fine.

My immediate thought is to set up a proxy server for the API. Your servers make requests to the proxy, it forwards the requests on to the API but also rate limits itself.

The other option is to get on the phone and see if you can work something out with the API provider so you have a higher limit.

Sorry, I forgot to include that it is fire-and-forgot, nothing about these requests needs to make it's way back to the systems. I probably should have explained this better but the requests come from an azure cloud service, not the clients themselves. The clients just send an alert to the cloud service that they are finished, and then the cloud service makes and sends the requests on behalf of the client. So in effect, I already have a central spot that the requests are being built & sent, but I don't have any rate limiting.

I'll take a look into the proxy server as well, I wasn't aware I could do that.

And I've already been on the phone with them and this is my only option.

Edit: I edited my first post on this to better explain how the current system works.

Essential fucked around with this message at 16:44 on Jul 31, 2015

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Essential posted:

So in effect, I already have a central spot that the requests are being built & sent, but I don't have any rate limiting.

I'll take a look into the proxy server as well, I wasn't aware I could do that.

Sounds like you should just build in rate limiting to the cloud service, then it is basically doing the same thing as the proxy would be. The only reason to use an actual proxy would be if the clients expected a response.

The benefit of using an actual queue like Azure Service Bus would be durability, e.g. if you are worried about the cloud service crashing before servicing pending rate-limited requests.

Bognar fucked around with this message at 18:17 on Jul 31, 2015

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Here's a dead simple async rate-limiter I just threw together:

C# code:
public class RateLimiter
{
	private int _delay;
	private Task _waitTask = Task.FromResult(0);
	private SemaphoreSlim _semaphore = new SemaphoreSlim(1);
	
	public RateLimiter(int delayMilliseconds)
	{
		_delay = delayMilliseconds;
	}
	
	public async Task WaitAsync()
	{
		await _semaphore.WaitAsync();
		await _waitTask;
		_waitTask = Task.Delay(_delay);
		_semaphore.Release();
	}
}
Dunno what your cloud service looks like, but using it with MVC might look like:

C# code:
public class MyController : Controller
{
    // static is important!
    private static readonly RateLimiter Limiter = new RateLimiter(250);

    public Task MyActionMethod()
    {
        await Limiter.WaitAsync();
        await DoThirdPartyApiCall();
    }
}
If anyone sees any glaring issues with this, let me know. I tested it all of once at https://dotnetfiddle.net/vik5OH

Bognar fucked around with this message at 18:36 on Jul 31, 2015

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Just ran into a VS2015 code suggestions bug.

code:
public enum Foo
{
    One,
    Two
}

$"{(int)Foo.One}, {Foo.One}"
It's saying the first cast is redundant, even though it changes the output.

SixPabst
Oct 24, 2006

Bognar posted:

Just ran into a VS2015 code suggestions bug.

code:
public enum Foo
{
    One,
    Two
}

$"{(int)Foo.One}, {Foo.One}"
It's saying the first cast is redundant, even though it changes the output.

I'd say because at compile your enum is just integers under the covers anyway so it is kind of redundant.

Essential
Aug 14, 2003

Bognar posted:

Here's a dead simple async rate-limiter I just threw together:

Wow, you're awesome, thank you!

I've never used SemaphoreSlim before, can you clarify how this works? Is the ratelimiter basically a 250 millisecond delay that creates it's own thread via SemaphoreSlim? And therefore it won't block the main thread?

This is a WCF Cloud Service and to be honest I don't have any idea/understanding of what thread(s) are in play. Because other methods in this wcf service are being called constantly, does using SemaphoreSlim make sure that no other methods are blocked? I'm not sure I'm even thinking about this right, I just know that all other methods handled by the cloud service must continue to function while the rate limiter is doing it's thing.

I also don't know what kind of performance impact this will have. We can always increase the performance on this server or I suppose create a new server just to handle this if it was ever necessary.

Sedro
Dec 31, 2008
A semaphore(1) is a mutex, so you can read it as a lock { ... } with async semantics. It will block on the async context, which by default uses the thread pool (which is quite smart at awaiting I/O without blocking threads).

That code ensures that at most one request happens every 250ms. That's quite aggressive--you really only need to throttle requests as you approach the rate limit.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

mintskoal posted:

I'd say because at compile your enum is just integers under the covers anyway so it is kind of redundant.

Except that the result of that interpolated string would be "0, One" so the cast is definitely not redundant.


Essential posted:

I've never used SemaphoreSlim before, can you clarify how this works? Is the ratelimiter basically a 250 millisecond delay that creates it's own thread via SemaphoreSlim? And therefore it won't block the main thread?

A semaphore is a synchronization primitive that only lets N things access it at once (where N here is one, aka a mutex). The C# SemaphoreSlim implementation allows us to wait on it asynchronously, so there shouldn't be any thread blocking.

The RateLimiter just uses the semaphore as a barrier to entry for its WaitAsync method (_semaphore.WaitAsync()), so only one task can be executing that code at once (released with _semaphore.Release()). The other two lines just wait on a delay task, then create a new delay task for the next caller to wait on.

The best real world example I can give is this. It's a room with two doors that has enough space for one person. There's a line out the front door for people waiting to get in. The front door only opens when the person inside the room has left through the back door. Inside the room is a timer - the back door unlocks only once the timer goes off and the person in the room restarts the timer.

Regarding the main thread, I don't think WCF Cloud Services have a "main" thread - not one that's relevant anyway. Requests are handled via different threads on the thread pool. When waiting asynchronously, threads are returned to the thread pool so you don't need to worry about blocking other methods. This also shouldn't impact performance in any noticeable way.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Sedro posted:

That code ensures that at most one request happens every 250ms. That's quite aggressive--you really only need to throttle requests as you approach the rate limit.

You mean the rate limit of one request every 200ms (5 per second)? I don't see how that's noticeably aggressive.



EDIT: Should have edited this into the above post, oh well.

Bognar fucked around with this message at 20:02 on Jul 31, 2015

Sedro
Dec 31, 2008
I mean, if you make 5 simultaneous requests then you don't need to throttle, only on the 6th.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
That's true, but it doesn't make much of a difference in the end if you're making enough requests to get you throttled. The main reason I didn't go with that way, though, is that the code isn't as simple to understand.

Essential
Aug 14, 2003

Bognar posted:

A semaphore is a synchronization primitive that only lets N things access it at once (where N here is one, aka a mutex). The C# SemaphoreSlim implementation allows us to wait on it asynchronously, so there shouldn't be any thread blocking.

The RateLimiter just uses the semaphore as a barrier to entry for its WaitAsync method (_semaphore.WaitAsync()), so only one task can be executing that code at once (released with _semaphore.Release()). The other two lines just wait on a delay task, then create a new delay task for the next caller to wait on.

The best real world example I can give is this. It's a room with two doors that has enough space for one person. There's a line out the front door for people waiting to get in. The front door only opens when the person inside the room has left through the back door. Inside the room is a timer - the back door unlocks only once the timer goes off and the person in the room restarts the timer.

Regarding the main thread, I don't think WCF Cloud Services have a "main" thread - not one that's relevant anyway. Requests are handled via different threads on the thread pool. When waiting asynchronously, threads are returned to the thread pool so you don't need to worry about blocking other methods. This also shouldn't impact performance in any noticeable way.

Got it, again thank you so much!

Regarding the aggressiveness, if I'm understanding this right, I could probably drop that down to 100ms or even a bit less on the RateLimiter. The actual request to the api will always take minimum 100ms to return back, just due to latency etc. Therefore, if the RateLimiter gives me a 100ms delay and the api request takes 100ms I'm at most 5 per second. Yes this is adding a delay even when one may not be necessary, but given how simple this is to implement I'm not sure that really matters.


VVVV I see, thanks! VVVV

Essential fucked around with this message at 20:51 on Jul 31, 2015

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Essential posted:

Got it, again thank you so much!

Regarding the aggressiveness, if I'm understanding this right, I could probably drop that down to 100ms or even a bit less on the RateLimiter. The actual request to the api will always take minimum 100ms to return back, just due to latency etc. Therefore, if the RateLimiter gives me a 100ms delay and the api request takes 100ms I'm at most 5 per second. Yes this is adding a delay even when one may not be necessary, but given how simple this is to implement I'm not sure that really matters.

Not exactly, this simple RateLimiter just throttles when you can start a request. If it's set to 100ms, then you'll start 10 requests per second. The end of a request isn't really taken into account.

The aggressiveness discussion was more about the difference between these two throttling modes:

5 requests, wait 1 second, 5 requests, wait 1 second, etc...
vs.
1 request, wait 200ms, 1 request, wait 200ms, etc...

SixPabst
Oct 24, 2006

Bognar posted:

Except that the result of that interpolated string would be "0, One" so the cast is definitely not redundant.

Right, you're writing out an integer value (Foo.One explicitly cast as an integer) and then writing Foo.One.ToString("g") (the default for Enum.ToString() which displays the enum entry as a string value).

ljw1004
Jan 18, 2005

rum

Bognar posted:

Just ran into a VS2015 code suggestions bug.

Please file this as a bug on github "dotnet\roslyn". I filed two other bugs about wrong "redundant cast" suggestions a couple of months ago. Both got fixed but I guess we didn't check this case.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

ljw1004 posted:

Please file this as a bug on github "dotnet\roslyn". I filed two other bugs about wrong "redundant cast" suggestions a couple of months ago. Both got fixed but I guess we didn't check this case.

Just did, thanks for the suggestion.

Calidus
Oct 31, 2011

Stand back I'm going to try science!
I am trying to use the MVC Entity scaffolding to create a some pretty standard views in VS2013 Update 5, but I keep getting: There was an error running the selected code generator 'Object reference not set to an instance of an object.' It seems to happen on all my classes. It is driving me batty, I have reinstalled Entity and reinstalled MVC in my projects and I repaired VS2013. I have WebTools installed. I even tried creating a new solution with a entity model and the mvc starter code but it still failed. The same thing also happens in VS2015.



edit: I have tried it on a coworkers machines and I get the same issue, so I guess it must be something with my solution/project.

Calidus fucked around with this message at 23:32 on Jul 31, 2015

EssOEss
Oct 23, 2006
128-bit approved
What is a good way to write out some files for debugging purposes from tests running in an UWP app? I am currently using ApplicationData.Current.LocalFolder but this seems to be deleted after the test runner process exits. I thought the Downloads folder might be a good place but nope, trying to create files via DownloadsFolder gives me some lovely "A parameter was incorrect" exception. I just want to save my debug output somewhere.

Mr Shiny Pants
Nov 12, 2012
In WinRT you can write to the Windows.ApplicationModel.Package.Current.InstalledLocation and it will leave them be. At least that is my experience. I don't know if it is different for UWP apps though.

This the %appdata%\local\packages\guid\localstate location IIRC.

EssOEss
Oct 23, 2006
128-bit approved
What's where LocalFolder puts them but the files are cleaned up when it is done. Possibly the cleanup is specific to running tests? Whatever the case, the files disappear after the test run.

Mr Shiny Pants
Nov 12, 2012

EssOEss posted:

What's where LocalFolder puts them but the files are cleaned up when it is done. Possibly the cleanup is specific to running tests? Whatever the case, the files disappear after the test run.

Is this the behaviour that you are seeing?
http://stackoverflow.com/questions/14245597/mstest-how-to-prevent-custom-log-file-from-being-deleted-and-prevent-trx-from

The King of Swag
Nov 10, 2005

To escape the closure,
is to become the God of Swag.
Maybe I'm just not understanding exactly at what level of the compilation process the safe navigation operator (?.) is working at, but despite developing using the .NET 4.0 runtime, VS2015 is recommending I use it, and sure enough, it actually works. So what's going on here? Is the compiler just compiling it in a way that it still functions with the older runtimes?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

The King of Swag posted:

Maybe I'm just not understanding exactly at what level of the compilation process the safe navigation operator (?.) is working at, but despite developing using the .NET 4.0 runtime, VS2015 is recommending I use it, and sure enough, it actually works. So what's going on here? Is the compiler just compiling it in a way that it still functions with the older runtimes?

Language version and .NET Framework versions are two different things, yes. The framework mostly just changes the libraries you work with.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

The King of Swag posted:

Maybe I'm just not understanding exactly at what level of the compilation process the safe navigation operator (?.) is working at, but despite developing using the .NET 4.0 runtime, VS2015 is recommending I use it, and sure enough, it actually works. So what's going on here? Is the compiler just compiling it in a way that it still functions with the older runtimes?

The compiler translates var someVar = thing1?.Thing2 to this (more or less):

C# code:
var temp = thing1;
var someVar = temp == null ? null : temp.Thing2;

Adbot
ADBOT LOVES YOU

Captain Capacitor
Jan 21, 2008

The code you say?

epalm posted:

Back from several business trips, sorry for the delayed responses!


I decided to bite the bullet and purchase developer support. When I try to open a support ticket, I'm asked to choose a subscription, and developer support isn't in the list. If I choose my BizSpark subscription, I'm asked to choose a support plan, and developer support isn't in the list. Now what.


How on earth would I go about solving such a problem while the app is live?


Am I the only one who thinks "well it only happens once a month" is unacceptable?

My resources are all in East US.


Yes.


Re-engineer my application because Microsoft doesn't like transactions? What??

:derp:

I'm doing an internal move today to a team that has put me in the position of being able to talk to the Azure product teams more directly. I've sent a message, but this applies to anyone who has an issue. I can't guarantee anything but I can now yell at people louder.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply