New answers tagged

0

Keep in mind if the is a network between your program and the database, it is very easy to write code that becomes IO bound. Also, if you are processing transactions you may have to take several trips to the database depending on the mechanism used to track transactions.


0

I did some research and testing and here are my results: Analysis We have several possibilities when reading and writing messages for web services under the .Net platform. Strongly Typed Classes using XmlSerializer Strongly Typed Classes implementing IXmlSerializable Strongly Typed Classes using Data Contract Serializer Loading to XElement/Document and ...


0

It's not about testing, it's about tuning. Since you're doing a lot of I/O, any sort of "CPU profiler" is not what you want. The method I always use is this. Here's what I would do if I were you: Tune the program until it is as fast as possible. Then if it is not fast enough to be satisfactory, get faster hardware. The way I would do it is take a number of ...


2

Eugene Philipov ran a benchmark on multiple INSERTs in one query and found out that they are really faster than running many sequential inserts after each other. This really did not come as a surprise because INSERT is a very simple operation. For updates the reason why you'd be taking multiple trips to a database is because the code is simply easier to ...


0

How do I know if my code is running fast enough? That very much depends on your use case -- your program runs for 1.4 hours which might or might not be fast enough. If this is a one-time process 1.4 hours is not that much - spending any time on optimization is hardly worth the investment. On the other hand, if this is a process that should run e.g. once ...


0

As others have noted, don't optimize unless the speed is unsatisfactory. You've moved on to the next step which is to profile. Once you've profiled its time to look for possible optimization candidates: Looking at your process which runs for 528 seconds. You have one call to OBSparser.py:48(parse) using 166 seconds. If you could totally eliminate ...


1

This is what non-functional requirements of performance are for. The notion of fast enough has nothing technical per se. It depends on user perception of your product, and should be translated through the requirements. This is the only objective way for you to tell whether your actual implementation is fast enough or not. If you don't have those ...


1

You have forgotten the most basic question: Is the speed satisfactory for the use case? If the answer is "yes" -> don't profile If no, you might look at your table. But honestly, it looks not terribly useful, because almost all time is spend in OBSparser.py:48(parse), which takes a LONG time. I would suggest you refactor that method into several ...


2

The first thing to realize is that the situation you describe (some items are 'never' processed) can only arise if you simply don't have the capacity to handle the volume of requests. If you have the capacity to handle the expected volume of requests over a given time period, you will be able to handle all the requests. This is a tautology. Changing the ...


6

The scheduling mechanism you have described is Fixed-priority pre-emptive scheduling. If you know there is a possibility the max priority queue is always full, then you are using the wrong mechanism, because of starvation as you described. You could prevent starvation by using a different scheduler. For instance, you can say that you process at most f(...


3

Basically you're making priority a function of two variables, like pricePaid*A + waitingTime*B. That's a perfectly sensible strategy. Suppose you're selling tickets, and the price people pay puts them into one of the queues - high, medium, low. You could look at that as a single ordered priority queue, where the priority is high, medium, or low. Within each ...


0

Because optimization for devices that are going out of fashion isn't a high business priority for Apple. Things don't often naturally get faster/better on their own, it's like the 2nd law of thermodynamics, natural tendency is towards disorder. See also open-closed principle (part of SOLID), systems are most often open for extension but closed for ...


3

Instantiating and collecting small, short-lived, temporary objects, is perfectly fine. It is what modern garbage collectors are good at. Modern (generational) garbage collectors are built on a couple of assumptions: most objects die young, most objects are small, most objects don't escape, most objects are immutable, older objects don't contain references ...


-1

Garbage collection can become a performance issue in games, and might require special approaches. However, before you are sure that garbage collection of temporary Location instances is problematic, you would waste your time by trying to limit the amount of instances: “Premature optimization is the root of all evil.” To decide whether you should go down ...


1

You could use java 8's Streams, which will do short-circuiting under the hood for you. To get around some boxing/unboxing you can define this internal interface : private interface SolutionTest { boolean test(int a, int b); } With this in place you can introduce these helper methods : private boolean isPossibleSolution(int c, int d) { return ...


1

I'm not sure if this is what you mean, but you can do such a thing with a labeled break/continue (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html): main: for (int d = 0; d <= max; d++) { subMain: for (int c = 0; c < d; c++) { boolean possibleSolution = test1(c,d); if(!possibleSolution) continue main;...


1

Based on your question break; will NOT work for you. You want to skip all further steps in this cycle, do c++ and go for a new round. This is done using continue. Break will end inner cycle do d++ and start inner cycle from 0.


5

Measure first instead of making assumptions. The sequence of 30 tests "if (possibleSolution)" is something that a good compiler should be able to optimise away. At the first "if (possibleSolution)" a good compiler would generate code that doesn't only skip one call, but figures out immediately that the second, third, and so on if are also going to fail, so ...


2

Replace If(pass) pass=testN(c,d); With If(!testN(c,d)) {break;} This way you get to a new cycle right away.


7

While Python's current implementation (which lacks a lot of the optimisations performed by other dynamic languages, e.g. modern Javascript implementations and, as you point out, Lua) is a source of most of its problems, it does have some semantic issues that would make it difficult for an implementation to compete with other languages, at least in certain ...


16

What semantic features of Python (and other dynamic languages) contribute to its slowness? None. Performance of language implementations is a function of money, resources, and PhD theses, not language features. Self is much more dynamic than Smalltalk and slightly more dynamic than Python, Ruby, ECMAScript, or Lua, and it had a VM that outperformed all ...


0

just like the other responders, i would really like to know what database this is. to answer your question, i would use a Distributed Lock Manager to ensure only one process can write to this database...ZooKeeper is one of the most popular implementations at the time a write this...Redis RedLock looks very promising.


0

Yes, it's certainly possible. Any computation that a CPU can do, a GPU can also do, and vice versa. But it's uncommon because: Engineering complexity While it is possible to run the same code on a CPU and GPU (e.g. CUDA), the processors have different abilities and performance characteristics. One is MIMD; the other, SIMD. What is fast on one is slow on ...


1

There is no point introducing a cluster of app servers fronted by a load balancer, if all are pointed at a common "database" which is not designed to handle concurrency. I wouldn't call it a database at all because that implies it handles concurrency as one expects from a modern DBMS. Since the requirement is you cannot change that piece of the ...


0

One real world example is the open source LuxRender rendering engine, which is capable of fully loading a CPU and GPU at the same time. In addition, it can load multiple GPUs at the same time and can also distribute across multiple computers. LuxRender uses OpenCL to facilitate this, although builds without OpenCL also exist. This is practical because ...


2

The database can only hold 1 write concurrently and does not support transactions. If this value is exceeded, the database responds immediately with an error code XXXXX. This is extremely bizarre for any modern database, but let's accept the premise. At a high-level, there are 2 approaches to concurrent data modifications: Pessimistic - This is lock-...


2

Reading the specs, the main point of your requirement is: An user should receive an immediate response that vote was accepted. To achieve that, you could separate out the vote-taking-part. Each of your two instances need to talk to a component responsible for that. Then the problem arises, this component becoming the bottleneck in your architecture. ...


0

The database can only hold 1 write concurrently and does not support transactions Lack of transaction is the main issue. I would suggest: If possible, update to a different RDBMS capable of transaction, e.g. Postgres. You really need ACID properties (or at least an RDBMS capable of locks), so that is the only honest and professional solution. otherwise, "...


1

You might be interested in checking out the Servo browser engine being developed at Mozilla Research, and more specifically its Web Render (video). While shifting a task from CPU to GPU dynamically might be impractical, as mentioned in other answers (notably @Philip's), it can be practical to study the load of CPU/GPU on typical workloads in advance and ...


10

From a supercomputing viewpoint it is better not to think in CPU/GPU load in percentage but rather determine how many operations your problem at hand needs and then compare that to the peak performance of the system. If you get 100% CPU utilization it does not necessarily mean that you get all the performance out of the system. CPUs can often do multiple ...


0

With a focus on games (since you mentioned it specifically in your post), there are some ways you can balance the load. One example is "skinning", i.e. animating a model. For each frame to be rendered, you have to generate the transformation matrices for each frame of animation and apply it to the vertices of the model to transform it into the pose it needs ...


60

Theoretically yes, but practically it's rarely worth it. Both CPUs and GPUs are turing-complete, so any algorithm which can be calculated by one can also be calculated by the other. The question is how fast and how convenient. While the GPU excels at doing the same simple calculations on many data-points of a large dataset, the CPU is better at more ...


34

It is not related to game programming. Some scientific code can also use both the GPU and the CPU. With careful -and painful- programming, e.g. by using OpenCL or CUDA, you could load both your GPU and your CPU near 100%. Very probably you'll need to write different pieces of code for the GPU (so called "kernel" code) and for the CPU, and some boring glue ...



Top 50 recent answers are included