how can I share CPU between two KVM VPS on a dedicated server?
assume that we have 8-core CPU on a dedicated server
to get maximum performance for two VPS, should I assign 8 cores to each one of them? or just assign 4 core to each VM?
You need to understand the needs of each VM and the threading limitations of the code you have, not every OS and application can make use of all the cores you can throw at it, very often there's zero benefit of expanding past a certain number of cores. The ideal scenario is that you allocate each VM what it needs, not less and ideally not more as that can actually slow down your system in some circumstances.
Assign as many vCPUs as you wish to any virtual guest, up to the number of physical CPU cores (or hyperthreads).
You can overcommit CPU by assigning more vCPUs among your running virtual machines than exist in the server, subject to the limit that no single virtual guest may have more vCPUs than physical CPU cores.
Keep in mind that if you have CPU intensive tasks, that overcommitting CPU won't buy you anything and may slow down the rest of your guests.