Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by mark24 · Jun 12, 2012 at 04:58 PM · servermathtreeslowphp

Moving computation to server

Hi all,

I am building a game to teach kids about ecosystems. We are generating the trees from info from a MySQL database about species, age, size, etc. There is a button to run a model that will simulate the real ecosystem going forward in time by one year; ie all the trees will grow, some will die, and some saplings will sprout. It is working now (mostly), but it is too slow (10-15 seconds per simulation year) since we are working with a 4 sq. km patch which has 100k-700k trees in a given year.

I would like to move the computation of the ecosystem model out of Unity and onto one of our servers via a php request (or something else). I was thinking that this would speed up the calculations. Does anyone have any experience doing this/any tips? Could I expect to shave anytime off of the simulation by moving the computation out of Unity?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Jun 12, 2012 at 05:02 PM 1
Share

This really depends on how fast your servers are. If you can run the simulations significantly faster on the database, then by all means do that, but if the database is not much faster than the clients themselves, this cannot possibly be efficient. $$anonymous$$eep in $$anonymous$$d that if you have many people running this at the same time, it could very quickly overload your servers if they are not extremely high-end, unless you plan to have one simulated 'world' shared between all users (in which case, simulating it on the server is the only thing that makes sense).

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Julien-Lynge · Jun 12, 2012 at 07:57 PM

Just to check: are you certain the bottleneck is in the calculations and not in the creation of gameObjects, procedural editing of meshes, etc? Creating more than a few hundred GameObjects at once can significantly slow down the main Unity thread - this is a bottleneck we've run into in our projects.

In terms of speed, Unity runs with a compiled Mono (.NET) backend, so it runs natively on the platform (as opposed to something like Java which runs in a virtual machine and can therefore be much slower). Without knowing your algorithms, it's hard to say where the bottleneck is - it could be memory allocation, it could be processor speed, it could be calls being blocked by other calls (inefficient code), etc. As syclamoth said, it only helps if your servers are going to solve your bottleneck. Then of course you have to figure out how much information you'll need to send to the server and what you'll get back - if you're trying to seamlessly move through time (rather than discretely change once per year) you may run into latency or bandwidth issues. If you would need to send more than a few kB of data per second, I'd suggest you rethink that route (and remember that 'bursts' of data can overwhelm MMO servers).

Have you looked into parallelization? Most computers these days have multiple cores, so you could change your model code to work in parallel. Unity functions (e.g. modifying a Component) aren't thread safe and can't be run this way, but pure calculations can definitely be shipped off to other threads.

On a final note: your project sounds very cool. We work in education too, and I'd love a link when you have a stable demo.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mark24 · Jun 13, 2012 at 12:36 PM 0
Share

Thanks for the advice! The creation of gameObjects is slowing it down a lot, but my plan is to do that less frequently than every model update (updated by year, discreetly). So I would only update the actual gameObjects if the player requests to time travel to the current state of the model. The gameObject creation and computation are separate methods, so I am definitely bottlenecking on my computation. I think, given your advice, I will start with computation on the server and try a separate thread if that doesn't work. Also I will be sure to send you a link once we get this up and running!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Players online counter 1 Answer

Upload a text file to my server? 0 Answers

php, sql security 3 Answers

Smart way of using servers and databases in unity 0 Answers

How to make multiplayer networking using C# as client and PHP as server,C# To PHP Server Based Multiplayer Game 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges