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.
 
  • Locked thread
Bloody
Mar 3, 2013

Luigi Thirty posted:

I'm going out so I'll harvest some answers while I'm gone

.net, c#. so, the user presses a button and it spawns a task to retrieve their backpack. that task spawns one task for each item in their backpack to get data from the steam api, but it's doing them in order, one after the other, so there's a lot of downtime waiting for http responses. how would I make it spawn all the individual item tasks at once and await their collective completion?

replace foreach(var foo in butts){...} with
Parallel.ForEach(butts, foo => {...});

if you don't want to spawn a lot of threads (eg if you know it's going to 100% a core or something) you can set an upper bound:

ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = /* number of threads, eg */ Environment.ProcessorCount - 1 };
Parallel.ForEach(butts, options, foo => {...});
that args order might be backwards but w/e

Adbot
ADBOT LOVES YOU

suffix
Jul 27, 2013

Wheeee!

prefect posted:

it takes too drat long (~20min) to create a new vm on our hardware :(

we autoprovision build slaves from docker images now, it works pretty well :toot:

zeekner
Jul 14, 2007

Bloody posted:

replace foreach(var foo in butts){...} with
Parallel.ForEach(butts, foo => {...});

if you don't want to spawn a lot of threads (eg if you know it's going to 100% a core or something) you can set an upper bound:

ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = /* number of threads, eg */ Environment.ProcessorCount - 1 };
Parallel.ForEach(butts, options, foo => {...});
that args order might be backwards but w/e

this, and make the max thread count somewhat low, most browsers only hit a server with 2-8 concurrent connections max. doing all of them at once will probably trigger flood limits or whatever.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Uncomfortable Gaze posted:

this, and make the max thread count somewhat low, most browsers only hit a server with 2-8 concurrent connections max. doing all of them at once will probably trigger flood limits or whatever.

I've done it in Python, I just don't know the c# way. one time I accidentally hit the api with 500 concurrent connections from a python script and tf2 items were down for an hour

zeekner
Jul 14, 2007

Luigi Thirty posted:

I've done it in Python, I just don't know the c# way. one time I accidentally hit the api with 500 concurrent connections from a python script and tf2 items were down for an hour

nice, did anything happen cause of it?

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Uncomfortable Gaze posted:

nice, did anything happen cause of it?

I emailed and asked if what I was doing was causing undue load on their server and they said they'd contact me if it did and they never have so :shrug:

of course I'm e-friends with the guy who writes the community pages so that probably helps

MononcQc
May 29, 2007

Bloody posted:

current hack solution: store the binary blobs on a network drive, send the path to the blob to use, call it "good enough"
As long as the blob is guaranteed to be stored and stable until consumed, that should be good enough indeed. You'll quickly see if you hit limits and the old scheme of resource-based systems based on some form of 'universal resource locator' has worked well enough for the web so far.

Bloody
Mar 3, 2013

MononcQc posted:

As long as the blob is guaranteed to be stored and stable until consumed, that should be good enough indeed. You'll quickly see if you hit limits and the old scheme of resource-based systems based on some form of 'universal resource locator' has worked well enough for the web so far.

:monocle:

tef
May 30, 2004

-> some l-system crap ->

MononcQc posted:

As long as the blob is guaranteed to be stored and stable until consumed, that should be good enough indeed. You'll quickly see if you hit limits and the old scheme of resource-based systems based on some form of 'universal resource locator' has worked well enough for the web so far.

host centric networking :argh:

MononcQc
May 29, 2007

tef posted:

host centric networking :argh:

Named Data Networking is interesting, but somewhat scary in that random nodes owned by whoever could decide to advertise what they want and deliver it how (slow) they want, without necessarily having a good way to say "I want that high-quality host".

Bloody
Mar 3, 2013

i made a distributed computing application and it didnt even take me that long :toot:

tef
May 30, 2004

-> some l-system crap ->

Bloody posted:

i made a distributed computing application and it didnt even take me that long :toot:

i hope your system works :toot: what happens when a machine fails? or the filesystem lies and is out of sync across machines? are actions on the filesystem atomic? what happens if it fails for a moment

Bloody
Mar 3, 2013

tef posted:

i hope your system works :toot: what happens when a machine fails? or the filesystem lies and is out of sync across machines? are actions on the filesystem atomic? what happens if it fails for a moment

machines send a keep alive message every minute; the server times out a machine if it doesnt talk for 10 minutes and adds its work back to the queue

the binary blobs are copied from the shared folder to the local file system and renamed to a guid before they're used (i was getting file lock bullshit otherwise). not brilliant because it recopies them every time it gets a new work unit, but copying ~100 megabytes locally is trivial compared to the time of the processing

the file system is read-only to the network. work unit results are only tens of kilobytes, so they are sent as messages to the server. the result logging process isn't atomic in that the server may log multiple results at once, but each result gets a uniquely named output file

if something fails for a moment (or even a while) like in terms of network connectivity i dont really know what happens but 0mq seems to handle it pretty gracefully. like i can turn on a client, wait a while, then start the server and the messages the client was trying to hit the server with zoom on through.

if the server reboots i have bigger problems for a variety of reasons. biggest probably being old work gets duplicated because it isn't saving its work unit queue anywhere. if it's ever a problem i'll probably bandaid it by looking at which work units we have results for and removing them at server startup.

on the whole this has been a kickass learning experience :toot:

JewKiller 3000
Nov 28, 2006

by Lowtax
nothing is atomic and someday your system will lose power in the middle of handling another failure

Bloody
Mar 3, 2013

JewKiller 3000 posted:

nothing is atomic and someday your system will lose power in the middle of handling another failure

luckily that doesnt matter because this is small scale monkeycheese

tef
May 30, 2004

-> some l-system crap ->
nothing is atomic, everything is permitted

Bloody
Mar 3, 2013

tef posted:

nothing is atomic, everything is permitted

but enough about your parents ah ah ha ha

Luigi Thirty
Apr 30, 2006

Emergency confection port.

you know from reading that blog a bunch it doesn't seem like windows is undocumented arcane weirdness as 20 years of bullshit stacked on top of bullshit required for compatibility with more bullshit that miraculously results in an occasionally functional operating system

thank god I don't have to do c++ windows programming

quote:

Windows defines many data types of the form pointer-to-X. These usually have the prefix P- or LP- in the name. For example, LPRECT is a pointer to a RECT, where RECT is a structure that describes a rectangle. The following variable declarations are equivalent.

code:

RECT*  rect;  // Pointer to a RECT structure.
LPRECT rect;  // The same
PRECT  rect;  // Also the same.

Historically, P stands for "pointer" and LP stands for "long pointer". Long pointers (also called far pointers) are a holdover from 16-bit Windows, when they were needed to address memory ranges outside the current segment. The LP prefix was preserved to make it easier to port 16-bit code to 32-bit Windows. Today there is no distinction — a pointer is a pointer.

Luigi Thirty fucked around with this message at 08:59 on Oct 3, 2014

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

tef posted:

i hope your system works :toot: what happens when a machine fails? or the filesystem lies and is out of sync across machines? are actions on the filesystem atomic? what happens if it fails for a moment

i think tef's just jealous and trying to hold back progress; he sounds like the people who are always talking poo poo about my perpetual-motion engine :smuggo:

Luigi Thirty
Apr 30, 2006

Emergency confection port.

prefect posted:

i think tef's just jealous and trying to hold back progress; he sounds like the people who are always talking poo poo about my perpetual-motion engine :smuggo:

my car that runs on water

i have found the fatal flaw: so .net is easy and winrt is easy but nobody uses win8 or the store! like my brother's been using win8 for a year and didn't know the store existed. i've been canvassing my steam friends to get them to install it and tell me what they think but they all run windows 7! :mad:

Bloody
Mar 3, 2013

c distributed system s: its whirring along beautifully :kimchi:

i wish i'd made the server better though

no logging, just console output
no database-backed work unit store
no way of adding new work units to the queue

oh well

Bloody
Mar 3, 2013

if i was actually confident i could reboot the server without frying the network then it wouldn't be so bad but i'm not that confident :v:

BONGHITZ
Jan 1, 1970

IM FLYING

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
I'm really wishing I had the insight two weeks ago that this data structure should be flipped from how I implemented it originally because trying to flip it now is a pita

syntaxrigger
Jul 7, 2011

Actually you owe me 6! But who's countin?

tef posted:

nothing is atomic, everything is permitted

hail eris

~Coxy
Dec 9, 2003

R.I.P. Inter-OS Sass - b.2000AD d.2003AD

Luigi Thirty posted:

my car that runs on water

i have found the fatal flaw: so .net is easy and winrt is easy but nobody uses win8 or the store! like my brother's been using win8 for a year and didn't know the store existed. i've been canvassing my steam friends to get them to install it and tell me what they think but they all run windows 7! :mad:

weird because win8 is up to 30% penetration on steam hardware survey

Bloody
Mar 3, 2013

~Coxy posted:

30% penetration
:smugmrgw:

Soricidus
Oct 21, 2010
freedom-hating statist shill

~Coxy posted:

weird because win8 is up to 30% penetration on steam hardware survey
that would be the significant minority who give gamers a bad name

Luigi Thirty
Apr 30, 2006

Emergency confection port.

is it weird that when Raymond Chen started complaining about games from a particular publisher using a dos extender that tried to gently caress with the gdt and gave cryptic errors when it wouldn't work I got it on the first try

(it was origin and their stupid loving dos extender that never worked right)

Luigi Thirty
Apr 30, 2006

Emergency confection port.

i'm trying to represent this bideo jame data in a database using EF. I have a model with a bunch of fields:

code:
public class GameItem
{      
        private int _id;
        private int _defindex;

        [Key]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public int Defindex
        {
            get { return _defindex; }
            set { _defindex = value; }
        }

        public virtual GameItemCapabilities Capabilities { get; set; }

	... more fields ...
}
and another model with a 1:1 relationship to the first model.

code:
public class GameItemCapabilities
{
        [Key, ForeignKey("GameItem")]
        public int Defindex { get; set; }

	... more fields ...
}
i want to match them up on the common Defindex field (I'd just use Defindex as the PK but it's 0-indexed and SQL server autoincrement PKs are 1-indexed and I haven't figured out how to change that from EF.). the objects get created properly but EF is generating a foreign key relationship called Defindex on the Id field so the inserts fail because they break the FK constraint. how do i make it generate the constraint on the right field?

Luigi Thirty fucked around with this message at 08:20 on Oct 5, 2014

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If there's a 1:1 relationship then there's no need to have a separate foreign key at all, both models should have the same key.

Is there actually a many:1 relationship going on? If so, in what direction?

Squinty Applebottom
Jan 1, 2013

I don't have a copy of visual studio handy, but theres a GUI representation if you click on your EF models in the object browser and you should be able to delete the FK somewhere around there.

they don't have migrations tho, do they? so you will probably have to load up ssms and also delete it from your current ables

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Jabor posted:

If there's a 1:1 relationship then there's no need to have a separate foreign key at all, both models should have the same key.

Is there actually a many:1 relationship going on? If so, in what direction?

no, it's 1:1.

the problem I'm having is when I make id the key, it auto assigns it when I save the database entries and overwrites what I assigned to it for some reason.

db.GameItem.Add(item) <-- id of 0
db.GameItemCapabilities.Add(item) <-- id of 0
db.Save() <-- both now have ids of 1 in the inspector!

db.GameItem.Add(item) <-- id of 1, exception because now there are too many items with an id of 1

Luigi Thirty fucked around with this message at 16:48 on Oct 5, 2014

Shaggar
Apr 26, 2006

Luigi Thirty posted:

i'm trying to represent this bideo jame data in a database using EF. I have a model with a bunch of fields:

code:
public class GameItem
{      
        private int _id;
        private int _defindex;

        [Key]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public int Defindex
        {
            get { return _defindex; }
            set { _defindex = value; }
        }

        public virtual GameItemCapabilities Capabilities { get; set; }

	... more fields ...
}
and another model with a 1:1 relationship to the first model.

code:
public class GameItemCapabilities
{
        [Key, ForeignKey("GameItem")]
        public int Defindex { get; set; }

	... more fields ...
}
i want to match them up on the common Defindex field (I'd just use Defindex as the PK but it's 0-indexed and SQL server autoincrement PKs are 1-indexed and I haven't figured out how to change that from EF.). the objects get created properly but EF is generating a foreign key relationship called Defindex on the Id field so the inserts fail because they break the FK constraint. how do i make it generate the constraint on the right field?

1) ORMs suck and EF sucks as an ORM
2) if your database has autoincrementing pks, then its the db that controls them, not the application and you shouldn't have the application rely on things being at certain ids so who cares if its 0 indexed. if you want to control all the ids, turn off auto-increment.


Luigi Thirty posted:

no, it's 1:1.

the problem I'm having is when I make id the key, it auto assigns it when I save the database entries and overwrites what I assigned to it for some reason.

db.GameItem.Add(item) <-- id of 0
db.GameItemCapabilities.Add(item) <-- id of 0
db.Save() <-- both now have ids of 1 in the inspector!

db.GameItem.Add(item) <-- id of 1, exception because now there are too many items with an id of 1

i hate ef so i don't use it much, but I think you need to create the item with the ef create method it should have built for your entity. if you're doing a code first thing then its probably lovely and a pain in the dick like all code-first approaches. the add method is to put an existing object into a new table. my guess is the first call to add also handles creation of the entity (which includes id assignment) and then when you call it again it fails cause it already exists. this is poo poo design and it should give you an error on the first add instead, but w/e. if you want to update an entity you have to use the modify method.

and all this is going on in this lovely bizarre in memory context that doesn't do anything until you save it, but it still throws errors if you try to do invalid calls which is awesome cause you cant tell if it came from EF enforcing the contracts it knows about or if it came from the database itself.

EF sucks hardcode

Shaggar fucked around with this message at 18:16 on Oct 5, 2014

Luigi Thirty
Apr 30, 2006

Emergency confection port.

what and write prepared sql statements like a barbarian

I mean I can do that but I figured in TYOOL 2014 there would be a better solution.

Shaggar
Apr 26, 2006
write procs in your db and call the procs from ur code. EF will let you use them as function imports which works ok but is not great.

Shaggar
Apr 26, 2006
the core problem with EF is it tries to maintain its own in memory version of the pieces of the database you're working with. That's the entitycontainer and where the entity in entity framework comes from. Its a way to abstract the concepts of entities in your code from however you store them, but the reality is everyone uses sql so the abstraction is pointless and adds a layer of confusion and boilerplate.

like orms suck in general but ef sucks even more than most.

Notorious b.s.d.
Jan 25, 2003

by Reene

Luigi Thirty posted:

what and write prepared sql statements like a barbarian

I mean I can do that but I figured in TYOOL 2014 there would be a better solution.

nhibernate

Squinty Applebottom
Jan 1, 2013

create table item capabilities
(
id int identity primary key
...

)

Adbot
ADBOT LOVES YOU

Luigi Thirty
Apr 30, 2006

Emergency confection port.

well yes the whole time I was doing it I was thinking "this would be so much easier if I just used SQL to do this poo poo since I know exactly what I want the database to do" so I'll just go and do that instead

  • Locked thread