Not really sure what you mean with "it only fails in the publication that save information in DataBase, in the rest of publications works", but the fact that you get a timeout during rendering of aprox. 500 Structure Groups sounds like you might have a database maintenance issue to start with.
Furthermore a Publish Transaction taking 1 hour really sounds like you are having a huge issue, that totally should not be happening. Even when you are publishing the entire Publication I would not expect it to take that long.
So to try and tackle the first issue I think that needs addressing, the database performance: The documentation has several topics on maintenance like http://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-94283420-8A51-4F2C-913E-B18455E58D74 and http://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-5863DEDC-1511-4333-A0C6-644B67403634
There is also an article on SDLs community website about database maintenance: https://community.sdl.com/products-solutions/solutions/customer_experience_cloud/digital-experience/tridion/tridion-developer/b/weblog/archive/2009/04/03/maintaining-sdl-tridion-databases
Basically it comes down to a correctly configured database server (please check the documentation of the database vendor for that) and making sure that you regularly update the statistics of the database and ensure the transaction log is properly truncated to keep it small.
For MS SQL Server, you can start with executing the following commands on the CM database:
And making sure the translation log is less than 1GB in size (because if it reaches that, your MS SQL Server database will become very slow).
I expect that after proper database maintenance you should see a lot better performance on Previewing and Publishing, and then we might be able to work on the problem which is reported at publish time (since the size issue will most likely still be there, but we will need more information to see how it can be solved). Please update your question and provide more details so we can continue on solving this.